Tutorial :SMTP exception while implementing email feature



Question:

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


Solution:1

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »