0

I've even turned on access to less secure apps on google but still im facing the same problem. It's working fine on my local system though. I keep getting the same error every time!

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

This is my code to send Mails

 private void demoMail(String greetings, String footer)
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "xxxxxxxxx");
            MailMessage msg = new MailMessage();
            msg.Subject = "A test Email xxxxxx";
            msg.IsBodyHtml = true;
            msg.Body = "This would be the email body xxxxxx";
            string toaddress = "somemail@gmail.com";
            msg.To.Add(toaddress);
            string fromaddress = "mymail@gmail.com";
            msg.From = new MailAddress(fromaddress);
            msg.Priority = MailPriority.High;
            try
            {
                smtp.Send(msg);
            }
            catch
            {
                throw;
            }
        }
zeus
  • 20
  • 2
  • Does this answer your question? [Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required](https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not) – Selim Yildiz Apr 23 '20 at 07:00
  • @SelimYıldız i've tried it but still the same – zeus Apr 23 '20 at 07:08
  • If You are using ssl, shouldn't it be port 465? – ivion Apr 23 '20 at 07:49
  • @ivion did the changes still its the same. – zeus Apr 23 '20 at 10:54

1 Answers1

0

This step worked for me! Also, make sure the google "Captcha" is disabled - this may be necessary if you are running the script on a remote server (not necessary when running on local machine): https://accounts.google.com/DisplayUnlockCaptcha
Solution by Jens

zeus
  • 20
  • 2