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.
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.
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.
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.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With