1

So im trying to send an email on C# and always getting the same error: "Additional information: The SMTP server requires a secure connection or the client was not authenticated." i have checked out pretty much every single link i could find about this i have diabled all gmail protection and my credentials are correct i don't know why this error continues

 MailMessage mail = new MailMessage();
        mail.From = new MailAddress("xx@gmail.com");
        mail.Sender = new MailAddress("xx@gmail.com");
        mail.To.Add("external@emailaddress");
        mail.IsBodyHtml = true;
        mail.Subject = "Email Sent";
        mail.Body = "Body content from";

        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.UseDefaultCredentials = false;

        smtp.Credentials = new System.Net.NetworkCredential("xx@gmail.com", "xx");
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.EnableSsl = true;

        smtp.Timeout = 30000;
        try
        {

            smtp.Send(mail);
        }
        catch (SmtpException ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }

2 Answers2

0

This is the exception message from C#, what is the actual response from the server? You may need to enable "less secure apps" to connect to your gmail account first (see https://www.google.com/settings/security/lesssecureapps).

Siderite Zackwehdex
  • 6,293
  • 3
  • 30
  • 46
0

I have tried your code getting the error "5.5.1 Authentication required". Please give this link a try Sending email through Gmail SMTP server with C#

kub0x
  • 159
  • 1
  • 7