实现电子邮件功能时的SMTP异常

时间:2010-07-03 06:51:30

标签: smtp

我在为本地计算机实现邮件功能时遇到异常请帮我解决这个问题

  

SMTP服务器需要安全   连接或客户端不是   认证。服务器响应   是:5.7.0必须发出STARTTLS   先命令。 21sm1768418wfi.5

1 个答案:

答案 0 :(得分:1)

正如消息所描述的那样。

除了提供用户名和密码外,您尝试连接的SMTP服务器除了提供用户名和密码外,还要求您为该连接使用SSL。

SMTP over SSL通常发生在端口465上,但是您需要与邮件提供商验证此设置。

因此,您需要指定正确的端口,并指定UseSSL标志。

使用C#可能如下所示:

 MailMessage mail = new MailMessage();
 SmtpClient SmtpServer = new SmtpClient("smtp.emailserver.com");

 mail.From = new MailAddress("your_email_address@yahoo.com");
 mail.To.Add("to_address@coolguy.com");
 mail.Subject = "Test Mail";
 mail.Body = "This is a test message";

 SmtpServer.Port = 465;
 SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
 SmtpServer.EnableSsl = true; //<--- this will do SSL for you.

 SmtpServer.Send(mail);