ASP.NET emailing to multiple emails

611 views Asked by At

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

2

There are 2 answers

1
Rab On BEST ANSWER

USE AddressCollection FOR ADDING MULTIPLE TO ADDRESSES LIKE

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

0
Thousand On

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
 }