tags:

views:

20

answers:

1

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

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 21sm1768418wfi.5

A: 

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("[email protected]");
 mail.To.Add("[email protected]");
 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);
Alan