gpt4 book ai didi

c# - 如何在 asp.net C# 中使用启用两因素身份验证的 office365 电子邮件帐户发送电子邮件?

转载 作者:行者123 更新时间:2023-12-04 11:36:47 24 4
gpt4 key购买 nike

我正在尝试使用 发送电子邮件office365 已启用 的电子邮件帐户双因素身份验证 .它给出了身份验证失败的错误。对于尚未启用双因素身份验证的电子邮件帐户,工作正常。如何解决这个问题?

using (SmtpClient client = new SmtpClient())
{
client.Port = Convert.ToInt32(appSettings["Port"]);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "smtp.office365.com";
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(SenderMailAddress, SenderMailPassword);
email.Subject = String.Format("{0}", txtMailSubject.Text);
//
email.Body = String.Format("{0}", text);

email.IsBodyHtml = true;

client.Send(email);
}

错误信息是

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated at System.Net.Mail.MailCommand.CheckResponse

最佳答案

            MailAddress from = new MailAddress("fromid");
MailAddress to = new MailAddress("toID");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"The sensor get offline ...";

SmtpClient client = new SmtpClient(server);
client.Host = "hostID";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential
{
UserName = "**********",
Password = "*************,
};
Console.WriteLine("Sending an email message to {0} using the SMTPhost {1}.");

关于c# - 如何在 asp.net C# 中使用启用两因素身份验证的 office365 电子邮件帐户发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55566016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com