开发者

SMTP exception while implementing email feature

I am getting following exception while implementing mail feature for my local machine please help me with this

The SMTP server requires a secure c开发者_如何学Goonnection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 21sm1768418wfi.5


It's exactly as the message describes.

What ever SMTP server you're trying to connect to, requires you to use SSL for that connection, in addition to supplying a username&password.

SMTP over SSL typically occurs on port 465, however you will need to verify this setting with your mail provider.

So you need to specify the correct port, and specify the UseSSL flag.

Using C# it might look like this:

 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜