0

I am trying to send an email to someone when they forget their password to their account but every time I try it says "The SMTP server requires a secure connection or the client was not authenticated. How do I fix this?

            mailLogin = new NetworkCredential(Email, Password);
            client = new SmtpClient("smtp.gmail.com");
            client.Port = 587;
            client.Credentials = mailLogin;
            client.EnableSsl = false;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            msg = new MailMessage { From = new MailAddress(Email, Name, Encoding.UTF8) };
            msg.To.Add(new MailAddress(Email));
            msg.Subject = "Subject";
            msg.Body = "Message";
            msg.BodyEncoding = Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.Normal;
            msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
            string userstate = "Sending...";
            client.SendAsync(msg, userstate);
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
OneWetBoy
  • 1
  • 4

1 Answers1

0

You need to set EnableSsl to true.

client.EnableSsl = true;

Then you must login to your google account and allow it to run less secure app (set to ON)

jgetner
  • 691
  • 6
  • 14