.NET System.Net.Mail.SmtpClient 使用注意事项

.NET System.Net.Mail.SmtpClient 使用注意事项: 

必须先设置UseDefaultCredentials, 然后再产生Credentials, 否则身份验证通不过:

System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为:Authentication required

      SmtpClient smtpClient = new SmtpClient();

      //smtpClient.UseDefaultCredentials = true;

      smtpClient.UseDefaultCredentials = false;

      smtpClient.Credentials = new System.Net.NetworkCredential(“<account name>”, “<password>”);

 

Leave a Reply

Your email address will not be published. Required fields are marked *