Send Email Using C# the Smtp Server Requires a Secure Connection or the Client Was Not Authenticated [Duplicate]

I was create sample email sender using c# but it shows an error is:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

private void SendHtmlFormattedEmail(string recepientEmail, string subject, string body)
{
    using (MailMessage mailMessage = new MailMessage())
    {
       mailMessage.From = new MailAddress("[email protected]");
       mailMessage.Subject = subject;
       mailMessage.Body = body;
       mailMessage.To.Add(new MailAddress(recepientEmail));
       SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
       smtp.EnableSsl = true;
       smtp.UseDefaultCredentials = false;
       System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential("[email protected]", "XXXXXXXXX");
       smtp.Credentials = NetworkCred;
       smtp.Timeout = 10000;
       smtp.Send(mailMessage);
    }
}

please help me for sample mail sender code

Status:System.Net.Mail.SmtpStatusCode.MustIssueStartTlsFirst

1

Try swapping these lines like so:

smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential NetworkCred = new    System.Net.NetworkCredential("[email protected]", "XXXXXXXXX");
2

I went to the following link:

and turned on the option Access for less secure apps

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest