我这里有这段代码......
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");
我的代码出了什么问题
答案 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
}