![](/img/trans.png)
[英]System.Net.Mail.SmtpException {“Failure Sending Email.”}
[英]Whitelist IP gmail smtp - System.Net.Mail.SmtpException: Failure sending mail
我有以下代码发送电子邮件。 它在本地运行良好,但是在hostgator Windows服务器上部署时,出现以下异常。
我想我需要在gmail somwhow中将我的服务器IP列入白名单,但是我该怎么做呢?
码:
var fromAddress = new MailAddress("XXX@gmail.com", "From XXX");
var toAddress = new MailAddress("XXX@gmail.com", "To XXX");
const string fromPassword = "XXX";
const string subject = "Email Headline";
string body = "Email Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
例外:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 173.194.77.109:587
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.