当前位置: 首页 > 知识库问答 >
问题:

电子邮件错误-SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 SMTP;

丁嘉庆
2023-03-14

我正在尝试通过我的 asp.net 应用程序发送电子邮件,但它抛出错误“SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.7.57 SMTP;客户端未通过身份验证,无法在来自 [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);

共有2个答案

从元明
2023-03-14

下面的代码适合我

    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);
        }
卢皓轩
2023-03-14

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

我已经看到的两个区别如下
-SmtpServer。EnableSsl=真
-新建SmtpClient(“smtp-mail.outlook.com”)

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

 类似资料: