nbi nbi - 1 year ago 239
C# Question

MailMessage.To.Add() throwing exception : "An invalid character was found in the mail header: ','."

I am getting this error when I am using it in sharepoint project, while in console app its working fine

I am using

class to send email using SMTP .
But when I trying to add user to 'To' property I am getting {"An invalid character was found in the mail header: ','."} exception, which I think something fishy is happening here as ',' is allowed to separate multiple users . Adding multiple user

** Multiple e-mail addresses must be separated with a comma character (",").**

MailMessage mailMessage = new MailMessage();


nbi nbi
Answer Source

Got the culprit: It's the extra comma(,) at the end of last email address


Just removed that and voila! its working. Don't know how that's working in console application but not in sharepoint :(

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download