我正在尝试使用以下代码从服务器发送带有我的gmailaccount的邮件。
var fromAddress = new MailAddress("xxxxx@gmail.com", "xxxxxx");
var toAddress = new MailAddress(toMailAddress);
const string fromPassword = "xxxxx";
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)
{
IsBodyHtml = true,
Subject = mailSubject,
Body = htmlBody
})
{
smtp.Send(message);
}
当我在Windows服务器上部署它时,这会给出下一个结果,尽管我在防火墙上有端口587的Inobound规则。当我测试本地时,它的工作非常完美
答案 0 :(得分:-1)
我也遇到过这个问题。实际上,Gmail不允许访问gmail以便为安全性较低的应用发送邮件。 执行以下步骤: 如果你得到像
这样的例外"An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
Additional information: 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"