0

Lots of examples of how to send emails using System.Net.Mail; but I read that there has been recent upgrades to mail servers so this code no longer works for both gmail or hotmail:

void sendMail(string ip) {
    SmtpClient SmtpMail = new SmtpClient("smtp.gmail.com");

    MailMessage msg = new MailMessage();
    msg.Subject = "MailTest";
    msg.Body = "MailTest";
    msg.From = new MailAddress("email@gmail.com");
    msg.To.Add("email@gmail.com");
    msg.Priority = MailPriority.High;
    SmtpMail.EnableSsl = true;
    SmtpMail.UseDefaultCredentials = true;
    SmtpMail.Credentials = new System.Net.NetworkCredential("email@gmail.com", "password"); 

    try
    {
        SmtpMail.Send(msg);
        oldIP = newIP;
    }
    catch (Exception ec) 
    {
        int xxx = 1;
    }
    
}

Does anyone know any working code?

My question was closed due to duplicate of this: Check the 'Less secure apps' setting in your gmail account. support.google.com/accounts/answer/6010255?hl=en – Shameel 1 hour ago

But i looked in to link and google says " This setting is no longer available. "

Also I don't get authentication error, code throws exception of "Failure sending mail" and that's it.

doggy
  • 75
  • 1
  • 8
  • Check the 'Less secure apps' setting in your gmail account. https://support.google.com/accounts/answer/6010255?hl=en – Shameel Sep 15 '22 at 02:12
  • This setting is no longer available. – doggy Sep 15 '22 at 03:54
  • I understand. Posting a link to the solution might help others who are visiting this question through google search. – Shameel Sep 16 '22 at 01:58
  • Google turned this feature off on May 30, 2022: https://support.google.com/accounts/answer/6010255?hl=en if you can't use the API or SDK, then App Passwords are your only option. https://support.google.com/accounts/answer/185833 just use the App Password instead of the account password in you current code – Chris Schaller Sep 17 '22 at 01:35

0 Answers0