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

时间:2020-05-26 15:29:19

标签: c# smtpclient

感谢您的帮助以解决此错误,我尝试了本例中提到的所有选项,但没有结果。 我的代码如下 我尝试从user@domainname.com使用,并在NetworkCredential中使用没有域的用户 还尝试使用端口25和587。

错误: 错误,SMTP服务器需要安全连接,或者客户端未通过身份验证。服务器响应为:5.7.57 SMTP;客户端未通过身份验证可以在[AM0PR10CA0008.EURPRD10.PROD.OUTLOOK.COM]的邮件中发送匿名邮件

代码:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                      | SecurityProtocolType.Tls11
                                                      | SecurityProtocolType.Tls12
                                                      | SecurityProtocolType.Ssl3;
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.From= new MailAddress("User@domain.com", "Name");
                msg.To.Add(new MailAddress(Email, Name));
                string fromPassword = "1234";
                msg.Subject= Subject;
                msg.Body= strMSG;
                msg.IsBodyHtml = true;
                msg.BodyEncoding = System.Text.Encoding.UTF8;

                SmtpClient smtp = new SmtpClient();
                smtp.Port =  587;
                smtp.Host = "smtp.office365.com";
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential("user", fromPassword, "domainName");

                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.EnableSsl = true;
                smtp.Timeout = 600000;
                smtp.TargetName = "STARTTLS/smtp.office365.com";

                smtp.Send(msg);    

0 个答案:

没有答案
相关问题