例外:
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);
}
答案 0 :(得分:0)
就像消息所述,您未经过身份验证。
在您的代码中:
string EmailFrom = "";
string EmailFromPassword = "";
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(EmailFrom, EmailFromPassword);
如果这是您的确切代码 - 您传递的是空用户名和密码..
答案 1 :(得分:0)
您需要检查以下详细信息是否正确(如Office 365面板上显示的详细信息)
代码看起来不错(假设您实际传递地址/密码,因为它是代码中的空白字符串),因此这可能是您设置中的问题。