Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I have a problem when i m run this code then error is occured that "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. "

And my code is:

Code

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

    MailMessage mail = new MailMessage();
    mail.To.Add("[email protected]");
    mail.From = new MailAddress("[email protected]");
    string body = "<table><tr><td>Company Name:</td><td>" + txt_cname.Text + "</td></tr><tr><td>Address With No.:</td><td>" + txt_addwithno.Text + "</td></tr><tr><td>Contact Person:</td><td>" + txt_conperson.Text + "</td></tr><tr><td>Email Id</td><td>" + txt_email.Text + "</td></tr><tr><td>Description</td><td>" + txt_description.Text + "</td></tr></table>";
    mail.Body = body;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;

    smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "12345");
    smtp.EnableSsl = true;
    smtp.Send(mail);


    txt_cname.Focus();
    txt_cname.Text = "";
    txt_addwithno.Text = "";
    txt_conperson.Text = "";
    txt_email.Text = "";
    txt_description.Text = "";

}
like image 943
Sanat Pandey Avatar asked May 22 '12 09:05

Sanat Pandey


People also ask

How do I fix SMTP authentication error?

SMTP connection can't be established If you have turned on the 2-factor authentication for your email account so you either need to turn it off or generate an app password for your email account. That app password can be used in your SalesHandy account to connect the email account via SMTP method.


1 Answers

Where are you hosting your website? Gmail prevents unrecognized access to your accounts. Try to execute this code and then go to you gmail and it will ask you if the access try was from you. Allow the application and you are done.

like image 164
Magnus Avatar answered Sep 20 '22 05:09

Magnus