THE SMTP SERVER REQUIRES A SECURE CONNECTION WHEN I TRY TO SEND AN EMAIL

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
C# 
C#
 1115  View(s)
Ratings:
Rate this:

I create a mail class to send emails. 

public void SendEmail(string subject, string messageBody, string toAddress)
{
    MailMessage mail = new MailMessage();
    mail.To.Add(toAddress);
    //mail.To.Add("amit_jain_online@yahoo.com");
    mail.From = new MailAddress("noreply3ncra@gmail.com");
    mail.Subject = subject;
    string Body = messageBody;
    mail.Body = Body;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = false;
 
    smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
    smtp.Credentials = new System.Net.NetworkCredential
         ("noreply3ncra@gmail.com", "********");
    //Or your Smtp Email ID and Password
    smtp.EnableSsl = true;
    smtp.Send(mail);
}

But I got this error: 

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

So I have to sign into Gmail and enter the captcha code and after this every thing is going to be ok. 

What should I do?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: The SMTP server requires a secure connection when i try to send an email

    Hi jay, 


    Add port no also to your code as:

     smtp.Port = 587;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!