How to send email to multiple address using System.Net.Mail

Denish picture Denish · Sep 21, 2011 · Viewed 156.8k times · Source

I have smtp email functionality. it works for single address but has problem in multiple address.

i am passing multiple addresses using following line of code.

MailAddress to = new MailAddress("[email protected],[email protected]");

Please let me know the problem as i am not getting any error.

Answer

Marco picture Marco · Sep 21, 2011
MailMessage msg = new MailMessage();
msg.Body = ....;
msg.To.Add(...);
msg.To.Add(...);

SmtpClient smtp = new SmtpClient();
smtp.Send(msg);

To is a MailAddressCollection, so you can add how many addresses you need.

If you need a display name, try this:

MailAddress to = new MailAddress(
    String.Format("{0} <{1}>",display_name, address));