【发布时间】:2019-09-15 04:52:33
【问题描述】:
我目前拥有的代码是:
public void SendEmail(string to, string cc, string bcc, string subject, string body, string attachmentPath = "", System.Net.Mail.MailPriority emailPriority = MailPriority.Normal, BodyType bodyType = BodyType.HTML)
{
try
{
var client = new System.Net.Mail.SmtpClient();
{
client.Host = "smtp-mail.outlook.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("[my company email]", "[my password]");
client.Timeout = 600000;
}
MailMessage mail = new MailMessage("[insert my email here]", to);
mail.Subject = subject;
mail.Body = body;
client.Send(mail);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我尝试发送到的电子邮件地址托管在 Office 365 的 Outlook 上。稍后我们可能必须更改特定地址,但它们的配置可能相同。
但是,每当我尝试运行 client.Send(mail); 命令时,都会收到相同的错误。错误全文为:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
我尝试了一些不同的方法,例如在 25 和 587 之间切换端口,将主机更改为 Office365,或者将 UseDefaultCredentials 和 EnableSssl 切换为 true 或 false。但我总是看到同样的错误。我还缺少什么吗?
【问题讨论】: