Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The server response was: 5.7.0 Must issue a STARTTLS command first. i16sm1806350pag.18 - gsmtp

I am trying to send mail using gmail, and I am getting an exception that is 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. i16sm1806350pag.18 - gsmtp

code I have written for sending mail is:

MailMessage mail = new MailMessage();  mail.To.Add(txtEmail.Text.Trim());  mail.To.Add("[email protected]"); mail.From = new MailAddress("[email protected]"); mail.Subject = "Confirmation of Registration on Job Junction."; string Body = "Hi, this mail is to test sending mail using Gmail in ASP.NET"; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); // smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); // smtp.Port = 587; //Or your Smtp Email ID and Password smtp.UseDefaultCredentials = false; // smtp.EnableSsl = true; smtp.Send(mail); 

Please tell me solutions, I am not getting any solutions for this exception.

like image 767
Ankur Gupta Avatar asked Jul 04 '13 05:07

Ankur Gupta


People also ask

What does 5.7 0 authentication required mean?

The server response was: 5.7. 0 Must issue a STARTTLS command first: This error means that the transport layer security (TLS) needs to be set to "Yes" in your SMTP settings. The SMTP server requires a secure connection or the client was not authenticated.

What is must issue a STARTTLS command first?

STARTTLS errors are mostly due to incorrect authentication settings. The settings are for Entourage but they are the same for Outlook 2011 as well. Was this reply helpful? By default you only need to enter the email address and password for a Gmail account unless you want to use as POP.

What is STARTTLS command in SMTP?

StartTLS is a protocol command used to inform the email server that the email client wants to upgrade from an insecure connection to a secure one using TLS or SSL. StartTLS is used with SMTP and IMAP, while POP3 uses the slightly different command for encryption, STLS.


2 Answers

Step (1): smtp.EnableSsl = true;

if not enough:

Step (2): "Access for less secure apps" must be enabled for the Gmail account used by the NetworkCredential using google's settings page:

like image 169
musmahn Avatar answered Sep 28 '22 01:09

musmahn


Gmail requires you to use a secure connection. This can be set in your web.config like this:

<network host="smtp.gmail.com" enableSsl="true" ... /> 

OR

The SSL should be enable on the webserver as well. Refer following link

Enabling SSL on IIS 7.0

like image 40
Microsoft DN Avatar answered Sep 28 '22 01:09

Microsoft DN