Send simple EMail

T

Tony M

VS 2005 - XP media - VB .net - winforms - .net 2.0



Just trying to send an email, here is the code and the error message that I
get. I can't figure out how to fix it?





'create the mail message

Dim mail As New MailMessage()

Dim smtp As New SmtpClient("http://mail.Someplace.com")

Dim WhatTimeIsIt As DateTime

mail.From = New MailAddress("(e-mail address removed)")

mail.To.Add("(e-mail address removed)")

WhatTimeIsIt = DateTime.Now

mail.Subject = "This is an email" & Format(WhatTimeIsIt) & " - "
& " winforms"

mail.Body = "this is a sample body"

'This next line didn't help error but i was getting error prior to putting
this line in.

smtp.Credentials = New Net.NetworkCredential("Username", "Secrete")

smtp.Send(mail)





-----------------Error Message -----------------------



System.Net.Mail.SmtpException was unhandled

Message="Failure sending mail."

Source="System"

StackTrace:

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at WinformsEMailtest.Form1.Button1_Click(Object sender, EventArgs e)
in C:\AllUserFiles\Movies\WinformsEMailtest\WinformsEMailtest\Form1.vb:line
28

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)

at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)

at System.Windows.Forms.Application.Run(ApplicationContext context)

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)

at WinformsEMailtest.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

------------------------------------------------------------------------------------------------------------------------------------------------------
 
T

Tom

You don't need HTTP:// in front of the SMTP server, it isn't http, so
you dont need it :)

Tony said:
VS 2005 - XP media - VB .net - winforms - .net 2.0



Just trying to send an email, here is the code and the error message that I
get. I can't figure out how to fix it?





'create the mail message

Dim mail As New MailMessage()

Dim smtp As New SmtpClient("http://mail.Someplace.com")

Dim WhatTimeIsIt As DateTime

mail.From = New MailAddress("(e-mail address removed)")

mail.To.Add("(e-mail address removed)")

WhatTimeIsIt = DateTime.Now

mail.Subject = "This is an email" & Format(WhatTimeIsIt) & " - "
& " winforms"

mail.Body = "this is a sample body"

'This next line didn't help error but i was getting error prior to putting
this line in.

smtp.Credentials = New Net.NetworkCredential("Username", "Secrete")

smtp.Send(mail)





-----------------Error Message -----------------------



System.Net.Mail.SmtpException was unhandled

Message="Failure sending mail."

Source="System"

StackTrace:

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at WinformsEMailtest.Form1.Button1_Click(Object sender, EventArgs e)
in C:\AllUserFiles\Movies\WinformsEMailtest\WinformsEMailtest\Form1.vb:line
28

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)

at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)

at System.Windows.Forms.Application.Run(ApplicationContext context)

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)

at WinformsEMailtest.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()
 
R

rowe_newsgroups

VS 2005 - XP media - VB .net - winforms - .net 2.0

Just trying to send an email, here is the code and the error message that I
get. I can't figure out how to fix it?

'create the mail message

Dim mail As New MailMessage()

Dim smtp As New SmtpClient("http://mail.Someplace.com")

Dim WhatTimeIsIt As DateTime

mail.From = New MailAddress("(e-mail address removed)")

mail.To.Add("(e-mail address removed)")

WhatTimeIsIt = DateTime.Now

mail.Subject = "This is an email" & Format(WhatTimeIsIt) & " - "
& " winforms"

mail.Body = "this is a sample body"

'This next line didn't help error but i was getting error prior to putting
this line in.

smtp.Credentials = New Net.NetworkCredential("Username", "Secrete")

smtp.Send(mail)

-----------------Error Message -----------------------

System.Net.Mail.SmtpException was unhandled

Message="Failure sending mail."

Source="System"

StackTrace:

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at WinformsEMailtest.Form1.Button1_Click(Object sender, EventArgs e)
in C:\AllUserFiles\Movies\WinformsEMailtest\WinformsEMailtest\Form1.vb:line
28

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)

at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)

at System.Windows.Forms.Application.Run(ApplicationContext context)

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)

at WinformsEMailtest.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

------------------------------------------------------------------------------------------------------------------------------------------------------

Also, Mcafee and other virus protection programs prevent
System.Net.Mail and System.Web.Mail from sending emails - it picks
them up as a mass mailing worm and generates the "Failure sending
mail" message. Be sure to add them to the list of allowed programs if
you think it will be a problem.

Thanks,

Seth Rowe
 
T

Tony M

Ok, I kind of got it to work thanks to you guys.
I can send some emails successfully to 2 servers only (or websites).
Everything else gives me the error listed below and I know they are good
addresses.
I also used (e-mail address removed) and same error (which is a place to test
email).
If I go to outlook (same computer same time) I can send to all these email
addresses without error.

"Mailbox unavailable. The server response was: <[email protected]> No
such user here"}
System.Net.Mail.SmtpFailedRecipientException'

Thanks again in advance


Tony M said:
VS 2005 - XP media - VB .net - winforms - .net 2.0



Just trying to send an email, here is the code and the error message that
I get. I can't figure out how to fix it?





'create the mail message

Dim mail As New MailMessage()

Dim smtp As New SmtpClient("http://mail.Someplace.com")

Dim WhatTimeIsIt As DateTime

mail.From = New MailAddress("(e-mail address removed)")

mail.To.Add("(e-mail address removed)")

WhatTimeIsIt = DateTime.Now

mail.Subject = "This is an email" & Format(WhatTimeIsIt) & " - "
& " winforms"

mail.Body = "this is a sample body"

'This next line didn't help error but i was getting error prior to putting
this line in.

smtp.Credentials = New Net.NetworkCredential("Username", "Secrete")

smtp.Send(mail)





-----------------Error Message -----------------------



System.Net.Mail.SmtpException was unhandled

Message="Failure sending mail."

Source="System"

StackTrace:

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at WinformsEMailtest.Form1.Button1_Click(Object sender, EventArgs e)
in
C:\AllUserFiles\Movies\WinformsEMailtest\WinformsEMailtest\Form1.vb:line
28

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)

at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(ApplicationContext context)

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)

at WinformsEMailtest.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()
 
T

Tony M

Nevermind I figured it out.
Incorrect credentials!
Works fin now thanks again


Tony M said:
VS 2005 - XP media - VB .net - winforms - .net 2.0



Just trying to send an email, here is the code and the error message that
I get. I can't figure out how to fix it?





'create the mail message

Dim mail As New MailMessage()

Dim smtp As New SmtpClient("http://mail.Someplace.com")

Dim WhatTimeIsIt As DateTime

mail.From = New MailAddress("(e-mail address removed)")

mail.To.Add("(e-mail address removed)")

WhatTimeIsIt = DateTime.Now

mail.Subject = "This is an email" & Format(WhatTimeIsIt) & " - "
& " winforms"

mail.Body = "this is a sample body"

'This next line didn't help error but i was getting error prior to putting
this line in.

smtp.Credentials = New Net.NetworkCredential("Username", "Secrete")

smtp.Send(mail)





-----------------Error Message -----------------------



System.Net.Mail.SmtpException was unhandled

Message="Failure sending mail."

Source="System"

StackTrace:

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at WinformsEMailtest.Form1.Button1_Click(Object sender, EventArgs e)
in
C:\AllUserFiles\Movies\WinformsEMailtest\WinformsEMailtest\Form1.vb:line
28

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)

at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)

at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(ApplicationContext context)

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)

at WinformsEMailtest.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top