0

I'm trying to create a contact form for a site where the user can fill out your basic info and email the form. In theory seems simple lots of articles but I'm getting an "Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required"

I started with these two Here & Here plus a few others. Then I ran into few errors stated above. Found an SO solution here. I've changed my password, make sure it was stronger and the right password. Enabled 2 set authentication and then disable two step authentication but still getting the error :

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

Any help is appreciated, or another way to do it. Thanks

Heres the code :

            MailMessage mm = new MailMessage("xxxxx@gmail.com", "xxxxxx@gmail.com");
        mm.Subject = txtSubject.Text;
        mm.Body = "Name: " + txtName.Text + "<br /><br />Email: " + txtEmail.Text + "<br />" + txtBody.Text;

        mm.IsBodyHtml = false;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;

        System.Net.NetworkCredential networkCred = new System.Net.NetworkCredential();

        networkCred.UserName = "xxxxx@gmail.com";
        networkCred.Password = "xxxxxxxx";
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = networkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        lblMessage.Text = "Email Sent Sucessfully";
Community
  • 1
  • 1
Troy Bryant
  • 994
  • 8
  • 29
  • 60

0 Answers0