Hello all,
I'm trying to send an Error log to multiple recipients (Group Admin, Manager and Project Lead) and I get various errors when I run the code. I can send the email with attachment to a single recipient but not multiples. Does anyone see the error in my code below?
The error thrown is for msgTo (An invalid character was found in the mail header: ';'.)
*******
Never Mind - I did a search on the forum for this error message and found the answer. Must use a comma not a semi-colon
Full error is below
System.FormatException was unhandled
HResult=-2146233033
Message=An invalid character was found in the mail header: ';'.
Source=System
StackTrace:
at System.Net.Mail.MailAddressParser.ParseLocalPart(String data, Int32& index, Boolean expectAngleBracket, Boolean expectMultipleAddresses)
at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)
at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data)
at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
at System.Net.Mail.MailAddressCollection.Add(String addresses)
at System.Net.Mail.Message..ctor(String from, String to)
at System.Net.Mail.MailMessage..ctor(String from, String to)
at ART_to_CSD_Feed.SendEmail.SendNewEmail(String Log) in C:\Users\BARNESR\Documents\Visual Studio 2012\Projects\ART to CSD Feed\ART to CSD Feed\SendEmail.vb:line 20
at ART_to_CSD_Feed.ART2CSDfrm.Startbtn_Click(Object sender, EventArgs e) in C:\Users\BARNESR\Documents\Visual Studio 2012\Projects\ART to CSD Feed\ART to CSD Feed\ArtToCSDfrm.vb:line 145
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.IMsoCompo nentManager.FPushMessageLoop(IntPtr 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 ART_to_CSD_Feed.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Thank you in advance,
-NJ
I'm trying to send an Error log to multiple recipients (Group Admin, Manager and Project Lead) and I get various errors when I run the code. I can send the email with attachment to a single recipient but not multiples. Does anyone see the error in my code below?
The error thrown is for msgTo (An invalid character was found in the mail header: ';'.)
*******
Never Mind - I did a search on the forum for this error message and found the answer. Must use a comma not a semi-colon
Full error is below
Code:
Public Function SendNewEmail(ByVal Log As String) As String
Dim ReturnedData As String
Dim smtpClient As New SmtpClient("XXX")
Dim smtpLogon As New NetworkCredential("XXX", "XXX")
Dim msgFrom As String = "XXX@.com"
Dim msgTo As String = "ABC@.com;DEF@.com;GHI@.com;JKL@.com;MNO@.com;PQR@.com"
Dim [from] As New MailAddress(msgFrom)
Dim [to] As New MailAddress(msgTo)
Dim Message As New MailMessage([from], [to])
Dim msgBody As String
msgBody = " "
Try
Message.Subject = "Art To CSD Feed has been processed on " + ART2CSDfrm.LogCurrentDateTime + " by " + ART2CSDfrm.UserName
msgBody = msgBody + "User " + ART2CSDfrm.UserName + " has processed the ART Feed - " + ART2CSDfrm.LogCurrentDateTime + vbCrLf
If Log <> "" Then
msgBody = msgBody + " " + vbCrLf
msgBody = msgBody + "An error log has been created - Please notify Kim " + vbCrLf
Dim attachments As New Mail.Attachment(Log)
Message.Attachments.Add(attachments)
'Message.Attachments.Add = ART2CSDfrm.CoCodeOutputFile
End If
Message.Body = msgBody
smtpClient.Send(Message)
Catch ex As Exception
MessageBox.Show("Error while sending email - " & ex.Message)
End Try
ReturnedData = "Success"
Return ReturnedDataSystem.FormatException was unhandled
HResult=-2146233033
Message=An invalid character was found in the mail header: ';'.
Source=System
StackTrace:
at System.Net.Mail.MailAddressParser.ParseLocalPart(String data, Int32& index, Boolean expectAngleBracket, Boolean expectMultipleAddresses)
at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)
at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data)
at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
at System.Net.Mail.MailAddressCollection.Add(String addresses)
at System.Net.Mail.Message..ctor(String from, String to)
at System.Net.Mail.MailMessage..ctor(String from, String to)
at ART_to_CSD_Feed.SendEmail.SendNewEmail(String Log) in C:\Users\BARNESR\Documents\Visual Studio 2012\Projects\ART to CSD Feed\ART to CSD Feed\SendEmail.vb:line 20
at ART_to_CSD_Feed.ART2CSDfrm.Startbtn_Click(Object sender, EventArgs e) in C:\Users\BARNESR\Documents\Visual Studio 2012\Projects\ART to CSD Feed\ART to CSD Feed\ArtToCSDfrm.vb:line 145
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.IMsoCompo nentManager.FPushMessageLoop(IntPtr 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 ART_to_CSD_Feed.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Thank you in advance,
-NJ