例外:
SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.1 客户端未通过身份验证
我没有使用Defaultcredentials
,所以我设置client.UseDefaultCredentials = false;
了另外,我提供了有效的电子邮件 ID 和密码、主机名和端口号;但是,我仍然得到相同的异常。我该如何解决这个问题?提前感谢您的帮助。
public void SendCustomerForgotPassword(string mailTo, string forgotUserId, string forgotPassword)
{
string mailSubject = "", mailBody = "";
mailSubject = "";
StringBuilder sbMailBody = new StringBuilder();
sbMailBody.AppendLine("Welcome to *****,");
sbMailBody.AppendLine("\r");
mailBody = sbMailBody.ToString();
SetSmtpClient(mailTo, mailSubject, mailBody);
}
private void SetSmtpClient(string recipients, string subject, string body)
{
string EmailFrom = "here set an email id";
string EmailFromPassword = "set password";
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(EmailFrom, EmailFromPassword);
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "pod51018.outlook.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.Send(EmailFrom, recipients, subject, body);
}