【问题标题】:Sending Email through SmtpClient smtp.office365.com Generating Error in ASP.Net, C# web forms通过 SmtpClient smtp.office365.com 发送电子邮件在 ASP.Net、C# Web 表单中生成错误
【发布时间】:2022-11-08 18:13:17
【问题描述】:

任何人都可以帮忙。

我正在使用以下代码从生成错误的 ASP.Net、C# Web 表单应用程序发送电子邮件。相同的代码适用于其他应用程序。我的域名中包含一个连字符 (-)。是这个原因吗?我是否需要查看电子邮件配置或服务器/域级别设置?请帮忙。

string smtpServer = "smtp.office365.com";
int port = 587;
using (MailMessage mail = new MailMessage())
{
    using (SmtpClient SmtpServer = new SmtpClient(smtpServer))
    {
        mail.From = new MailAddress(_emailIDFrom);
        mail.To.Add(_emailIDTo);
        mail.Subject = _subject;
        mail.IsBodyHtml = true;
        mail.Body = _emailBody;
        SmtpServer.Port = port;
        SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
        SmtpServer.UseDefaultCredentials = false;
        SmtpServer.Credentials = new System.Net.NetworkCredential(_emailIDFrom, _emailIDFromPassword);
        SmtpServer.EnableSsl = true;
        try
        {
            SmtpServer.Send(mail);
            return true;
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
            return false;
        }
    }
}

我在 Global.asax Application_Start 中的 Tls 代码如下

if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
{
    ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
}

错误 - SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 客户端未通过身份验证发送邮件。错误:535 5.7.139 身份验证不成功,租户的 SmtpClientAuthentication 已禁用。访问https://aka.ms/smtp_auth_disabled 了解更多信息。 [DXXP273CA0023.AREP273.PROD.OUTLOOK.COM]

【问题讨论】:

  • 任何人都可以帮助我吗?
  • 你已经解决了吗?

标签: asp.net c#-4.0 exchange-server c#-3.0 c#-2.0


【解决方案1】:

关于这个问题的任何更新?如果有人能回答这个问题,那将是一个帮助。

【讨论】:

    猜你喜欢
    • 2018-08-17
    • 2021-06-23
    • 2021-08-02
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 2013-02-22
    相关资源
    最近更新 更多