Vetrivel mp Vetrivel mp - 2 months ago 12
C# Question

Multiple address in MailAddress constructor

i was trying to add multiple to address like this.

MailAddress mailAddressTo = new MailAddress("sample@google.com;sample1@google.com","Vetrivelmp");


but throws error like

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

Answer

you cannot use the MailAddress constructor for specifying multiple receipts but you have to use the MailMessage object as showed below

...
MailMessage mail = new MailMessage();
mail.To.Add("me@mycompany.com,him@hiscompany.com,her@hercompany.com");
...

another way is:

MailMessage msg = new MailMessage();
msg.To.Add("person1@domain.com");
msg.To.Add("person2@domain.com");
msg.To.Add("person3@domain.com");
msg.To.Add("person4@domain.com");