Trying to send the message to my Gmail account.

Mar 1 2021 1:00 PM
I'm trying to send the message to my Gmail account through SMTP. And here is my code.
  1. try  
  2.            {  
  3.                MailMessage msg = new MailMessage();  
  4.                msg.From = new MailAddress("[email protected]");  
  5.                msg.To.Add("[email protected]");  
  6.                msg.Subject = "test";  
  7.                msg.Body = "Test Content";  
  8.                msg.Priority = MailPriority.High;  
  9.                SmtpClient client = new SmtpClient();  
  10.                client.UseDefaultCredentials = false;  
  11.                client.Credentials = new NetworkCredential("[email protected]""123""smtp.gmail.com");  
  12.                client.Host = "smtp.gmail.com";  
  13.                client.Port = 587;  
  14.                client.DeliveryMethod = SmtpDeliveryMethod.Network;  
  15.                client.EnableSsl = true;  
  16.                client.Send(msg);  
  17.            }  
  18.            catch (Exception ex)   
  19.            {  
  20.                throw ex;  
  21.            }  
 
It's throwing the exception "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required" 
 
 
 
 

Answers (6)