以下代码在本地计算机上使用时有效,但在服务器(HostGator)上发布多个电子邮件时失败。如果我尝试向一个人发送电子邮件,它也有效。
public void SendMailToMultiples(MailAddress fromAddress, string fromPassword, MailAddressCollection toAddress, string subject, string body)
{
MailMessage message = new MailMessage(){
Subject = subject,
IsBodyHtml = true,
Body = body,
From = fromAddress
};
foreach(var email in toAddress)
{
message.To.Add(email.Address);
}
var smtp = new SmtpClient
{
Host = HOST_NAME,
Port = PORT_NUMBER,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
{
smtp.Send(message);
}
}