ASP.NET通过电子邮件发送到多封电子邮件

时间:2012-06-07 18:13:17

标签: c# asp.net mailaddress

我这里有这段代码......

MailAddress from = new MailAddress("noreply@fakeemail.com", "IPC Orders");
        MailAddress to = new MailAddress("email1@fakeemail.com.com");
        MailMessage mail = new MailMessage(from, to);
        mail.To.Add("email2@fakeemail.com");
        mail.To.Add("email3@fakeemail.com");

显然这不是完整的代码,但是当我尝试向多个电子邮件地址发送电子邮件时,如果我将这两行注释掉的话......

        mail.To.Add("email2@fakeemail.com");
        mail.To.Add("email3@fakeemail.com");

可行并将其发送到第一封电子邮件MailAddress to = new MailAddress("email1@fakeemail.com.com");

我的代码出了什么问题

2 个答案:

答案 0 :(得分:2)

USE AddressCollection添加多个TO地址 LIKE

mail.To = new AddressCollection(“email2@fakeemail.com,email3@fakeemail.com”);

答案 1 :(得分:0)

您可以尝试添加将所有电子邮件地址添加到列表中,然后迭代该列表并在每个元素上发送邮件

List<string> emailAddress = new List<string>();
emailAddress.add("email1@em.com");
emailAddress.add("email2@em.com"); // ... etc


 foreach (string email in emailAddress)
 {
  MailMessage mail = new MailMessage(from, email);
  //+ more stuff
 }