我正在windows azure上运行一个ASP.Net应用程序,我需要从它发送一封电子邮件。我想使用我的Gmail帐户如下发送它,但是当我试图把它,我得到以下错误:SMTP服务器需要一个安全连接-gmail
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
代码:
private static readonly string EMAIL_ADDRESS = "[email protected]";
private static readonly string EMAIL_FROM = "MY FROM NAME";
private static readonly string EMAIL_PASS = "my Password";
private static readonly string EMAIL_HOST = "smtp.gmail.com";
private static readonly int EMAIL_PORT = 587;
private static readonly bool EMAIL_SSL = true;
private static readonly SmtpDeliveryMethod EMAIL_DELIVERY_METHOD = SmtpDeliveryMethod.Network;
private static readonly bool EMAIL_DEFAULT_CREDENTIALS = false;
public static void SendEmail(string recipientEmail, string subject, string body) {
var fromAddress = new MailAddress(EMAIL_ADDRESS, EMAIL_FROM);
var toAddress = new MailAddress(recipientEmail, "MY CLIENT NAME");
var smtp = new SmtpClient {
Host = EMAIL_HOST,
Port = EMAIL_PORT,
EnableSsl = EMAIL_SSL,
DeliveryMethod = EMAIL_DELIVERY_METHOD,
UseDefaultCredentials = EMAIL_DEFAULT_CREDENTIALS,
Credentials = new NetworkCredential(fromAddress.Address, EMAIL_PASS,EMAIL_HOST)
};
using (var message = new MailMessage(fromAddress, toAddress) {
Subject = subject,
Body = body,
Priority = MailPriority.High
}) {
smtp.Send(message);
}
}
我已经启用安全性较低的登录在,配置似乎很好。问题是什么?
尝试将第三个参数留给networkcredentials为空,也许看看sendgrid或类似的天蓝色使用 – jakobandersen
我试过没有第三个参数,结果相同。如果可能,我宁愿保持这一点。这应该从我看到的。 – mangusbrother
也许这是一个副本:http://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not如果你在与Azure数据中心不同的时区 – jakobandersen