An invalid character was found in the mail header: ';' in c#

foreach (var address in List1.split(';')) {
    mailMessagePlainText.To.Add(new MailAddress(address.Trim(), ""));
}

Because according to your string here above, each address in this loop above would produce following:

"[email protected]"
" [email protected]"
" [email protected]"
" [email protected]"

So by adding .Trim() to address would make your code work.


A MailAddressCollection (like your mailMessagePlainText.To) has an Add method that accepts a string containing a list of mail addresses, separated by a comma.

So to use that, you will need to change the ; into a , and possibly remove the extra spaces.

Tags:

C#

Email