使用smtpclient.send发送多封电子邮件 - 无法正常工作

时间:2013-03-31 16:38:20

标签: c# asp.net-mvc smtp smtpclient

以下代码在本地计算机上使用时有效,但在服务器(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);
        }
    }

0 个答案:

没有答案