當我試圖通過我的C#代碼發送郵件上面的錯誤顯示。我已經搜索可能的所有解決方案,但我沒有得到解決方案。我使用下面的代碼:SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應是:5.7.57 SMTP;
MailMessage mail = new MailMessage("SenderMail",Email);
mail.IsBodyHtml = true;
mail.Subject = "An email from Office365";
mail.Body = "<html><body><h1>Hello world</h1></body></html>";
SmtpClient client = new SmtpClient("smtp.office365.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false; // Important: This line of code must be executed before setting the NetworkCredentials object, otherwise the setting will be reset (a bug in .NET)
NetworkCredential cred = new System.Net.NetworkCredential("Sendermail", "Password");
client.Credentials = cred;
client.Send(mail);
您是否100%確定憑據(用戶:Sendmail,密碼:密碼)是否正確,包括大小寫? – Neil
是Neil I Cross通過登錄我的賬戶進行檢查@Neil –
SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應是:5.7.57 SMTP;客戶端未通過身份驗證發送匿名郵件[MA1PR01CA0093.INDPRD01.PROD.OUTLOOK.COM] –