【问题标题】:Email error -The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP;电子邮件错误 - SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 SMTP;
【发布时间】:2017-12-05 06:15:16
【问题描述】:

我正在尝试通过我的 asp.net 应用程序发送电子邮件,但它抛出错误“SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 SMTP;客户端未通过身份验证在 MAIL FROM [SG2PR0601CA0003.apcprd06.prod.outlook.com] 期间发送匿名邮件”

       MailMessage message = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
        message.From = new MailAddress("xxx@outlook.com");
        message.To.Add("xxx@gmail.com");
        message.Subject = "Test Email";
        message.Body = "Email Body";
        SmtpServer.Port = 587;
        SmtpServer.Credentials = new 
         System.Net.NetworkCredential("xxx@outlook.com", "xxxxxxxx");
        //SmtpServer.EnableSsl = true;
        SmtpServer.Timeout = 60000; // 60 seconds
        SmtpServer.Send(message);

【问题讨论】:

标签: c# asp.net email outlook


【解决方案1】:

1) 登录 owa (www.outlook.com) 检查帐户凭据
2) 请检查下面的链接,因为这将是您问题的解决方案
https://www.codeproject.com/Articles/700211/Csharp-SMTP-Configuration-for-Outlook-Com-SMTP-Hos

我已经看到的 2 个不同之处如下
- SmtpServer.EnableSsl = true;
- new SmtpClient("smtp-mail.outlook.com")

文章中还有一个很酷的部分“使用应用程序密码而不是 Outlook.Com 帐户密码”

【讨论】:

  • 它抛出错误“服务器不支持安全连接。”当我改变 SmtpServer.EnableSsl = true;
  • 尝试了所有这些,我的登录凭据很好,我可以登录 www.outlook.com,但仍然出现同样的错误。
  • 您是否尝试过使用我提到的article 中的代码?也许创建一个新的测试项目并将该代码与您的凭据一起使用
【解决方案2】:

下面的代码对我有用

    System.Net.Mail.AlternateView htmlView = null;
        string from = "xxx@outlook.com";
        using (MailMessage mail = new MailMessage(from, txtEmail.Text.Trim()))
        {
            mail.Subject = "Json File";
            htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body><div style='border-style:solid;border-width:5px;border-radius: 10px; padding-left: 10px;margin: 20px; font-size: 18px;'> <p style='font-family: Vladimir Script;font-weight: bold; color: #f7d722;font-size: 48px;'>Kindly find the Attachment.</p><hr><div width=40%;> <p  style='font-size: 20px;'>Thanks</div></body></html>", null, "text/html");
            mail.AlternateViews.Add(htmlView);
            mail.IsBodyHtml = true;
            System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType();
            contentType.MediaType = System.Net.Mime.MediaTypeNames.Application.Octet;
            contentType.Name = "New-Assign04.json";
            mail.Attachments.Add(new Attachment(Server.MapPath("~/App_Data/New-Assign04.json"), contentType));
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp-mail.outlook.com";
            smtp.EnableSsl = true;
            NetworkCredential networkCredential = new NetworkCredential("xxx@outlook.com", "xxxxxxxx");   // username and password
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = networkCredential;
            smtp.Port = 587;
            smtp.Send(mail);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多