i was trying to add multiple to address like this.
MailAddress mailAddressTo = new MailAddress("[email protected];[email protected]","Vetrivelmp");
but throws error like
An invalid character was found in the mail header: ';'
You cannot use the MailAddress
constructor for specifying multiple receipts, but you can to use the MailMessage
object as showed below.
Using the MailMessage
(not MailAddress
) constructor:
var msg = new MailMessage("[email protected]", "[email protected], [email protected]");
another way is:
MailMessage mail = new MailMessage();
mail.To.Add("[email protected],[email protected],[email protected]");
another way is:
MailMessage msg = new MailMessage();
msg.To.Add("[email protected]");
msg.To.Add("[email protected]");
msg.To.Add("[email protected]");
msg.To.Add("[email protected]");
Actually, semicolon is not a valid delimiter. Unfortunately, MSDN does not document this, had to find out this by myself.
If you want to add more addresses, divide them by comma. And the space will divide display name and email address. The "To" property accepts following formats:
[email protected]
[email protected]
, [email protected]
"[email protected]
"[email protected]
, [email protected]
"etc...
I wrote more about this topic in this blog post
Use a comma (,) as the separator instead of semicolon (;).
If multiple e-mail addresses separated with a semicolon character (";") are passed in the addresses parameter. a FormatException exception is raised.
Examples that work
MailAddressCollection.Add(String):
using (MailMessage msg = new MailMessage())
{
...
msg.To.Add("[email protected], [email protected]");
...
}
MailAddressCollection.Add(MailAddress):
using (MailMessage msg = new MailMessage())
{
...
msg.To.Add(new MailAddress("[email protected]", "Vetrivelmp"));
msg.To.Add(new MailAddress("[email protected]", "Vetrivelmp1"));
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With