0

I know this question has been posted many times before, and I have tried the solutions from the existing posts but with no success, and by solutions I mean changing the password from the GMail account to a stronger one and turning on access for less secure apps. The error message that I still get is:

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

I understand from this that the gmail server will not authenticate the account.

The code for the app is as follows:

private void button1_Click(object sender, EventArgs e)
    {

        MailMessage mail = new MailMessage();
        mail.To.Add("mail@domain.com");
        mail.From = new MailAddress("xxx@gmail.com");
        mail.Subject = textBox3.Text;
        string Body = richTextBox1.Text;
        mail.Body = Body;
        mail.IsBodyHtml = true;

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;

        smtp.Credentials = new System.Net.NetworkCredential("xxx@gmail.com", "xxxxxxx");// Enter seders User name and password 
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.Send(mail);
    }

Any help would be much appreciated as I am facing the problem for 2 days now.

Filburt
  • 17,626
  • 12
  • 64
  • 115
Bogdan U
  • 153
  • 2
  • 14
  • Possible duplication http://stackoverflow.com/questions/29958229/send-email-using-gmail-error-the-server-response-was-5-5-1-authentication-req – Andrii Tsok Nov 03 '15 at 08:09
  • See the links in my answer it should help, they are about the security settings: http://stackoverflow.com/questions/27695489/send-email-after-button-click-in-asp-net-c-sharp/27695675#27695675 – mybirthname Nov 03 '15 at 08:14
  • As I mentioned in the description I have seen the previous posts and tried their approaches with no luck. So why mark as duplicate guys? @mybirthname the code snippet from your answer worked like a charm ! You could post it also here as an answer for a +1! Thank you! – Bogdan U Nov 03 '15 at 08:34
  • @BogdanU I don't post it, because is duplicate and you don't need the code, you need to see the links in the answer. You need to turn off some settings in your google account. – mybirthname Nov 03 '15 at 08:35

0 Answers0