0

I'm trying to send an email using System.Net.Mail and am having some issues. It works as intended in the production environment("IIS Express(Google Chrome)" on Visual Studio, apologies if my terminology isn't clear). However, once I publish and create a public domain with (my domain).azurewebsites.net, I get the error:

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

Allow less secure apps is on, and upon the first attempt to sign in I got a "suspicious sign in attempt" on Google which I verified as me. Here is the calling code:

            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.Credentials = new NetworkCredential("myemail@gmail.com", "mypassword");

I can't seem to find anything on this, so my problem is either rare and complex or I'm being very silly. I strongly lean towards the latter, but I'd really appreciate any insight.

Patrick
  • 39
  • 1
  • 6
  • See if this helps https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not#:~:text=solution%20for%20case%201%3A%20Enter,to%20login%20from%20all%20apps.&text=Use%20that%20newly%20generated%20password%20to%20authenticate%20via%20SMTP. – TheGeneral Jan 18 '21 at 02:07
  • Already did everything there that's relevant (situation 1 and 3). – Patrick Jan 18 '21 at 02:49
  • Does this answer your question? [Sending mail from C# application](https://stackoverflow.com/questions/33457668/sending-mail-from-c-sharp-application) – Ali reza Soleimani Asl Dec 24 '22 at 15:45

1 Answers1

0
  1. Log in to the production server via remote access, and sign in to Gmail once with your credentials. They will ask for the confirmation, confirm it, and log out.

Or

  1. log in to Gmail to your local computer, Follow this Link and choose to review this activity, and take proper actions.

Check here for details: https://stackoverflow.com/a/26709761/11573842

MD. RAKIB HASAN
  • 3,670
  • 4
  • 22
  • 35
  • Don't have access to production server, and I already followed the link and reviewed the activity as mentioned in the original post. – Patrick Jan 18 '21 at 14:06