1

I have this code here...

MailAddress from = new MailAddress("[email protected]", "IPC Orders");
        MailAddress to = new MailAddress("[email protected]");
        MailMessage mail = new MailMessage(from, to);
        mail.To.Add("[email protected]");
        mail.To.Add("[email protected]");

Obviously this is not the full code, but when I try to send an email to multiple email address is doesnt send, if I comment out these two lines...

        mail.To.Add("[email protected]");
        mail.To.Add("[email protected]");

It works and will send it to the first email MailAddress to = new MailAddress("[email protected]");

Whats wrong with my code

user979331
  • 11,039
  • 73
  • 223
  • 418

2 Answers2

2

USE AddressCollection FOR ADDING MULTIPLE TO ADDRESSES LIKE

mail.To = new AddressCollection( "[email protected], [email protected]");

Raab
  • 34,778
  • 4
  • 50
  • 65
0

you can try to add add all your email addresses to a list, then just iterate over that list and send a mail at each element

List<string> emailAddress = new List<string>();
emailAddress.add("[email protected]");
emailAddress.add("[email protected]"); // ... etc


 foreach (string email in emailAddress)
 {
  MailMessage mail = new MailMessage(from, email);
  //+ more stuff
 }
Thousand
  • 6,562
  • 3
  • 38
  • 46