I'm trying to send the message to my Gmail account through SMTP. And here is my code.
- try
- {
- MailMessage msg = new MailMessage();
- msg.From = new MailAddress("[email protected]");
- msg.To.Add("[email protected]");
- msg.Subject = "test";
- msg.Body = "Test Content";
- msg.Priority = MailPriority.High;
- SmtpClient client = new SmtpClient();
- client.UseDefaultCredentials = false;
- client.Credentials = new NetworkCredential("[email protected]", "123", "smtp.gmail.com");
- client.Host = "smtp.gmail.com";
- client.Port = 587;
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- client.EnableSsl = true;
- client.Send(msg);
- }
- catch (Exception ex)
- {
- throw ex;
- }
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"


Tamil RkRank #4,239 · 356 reputationPosted Mar 2, 2021, 3:07 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Mar 1, 2021, 8:14 AM EST
Salman BegRank #284 · 8.8K reputationPosted Mar 1, 2021, 8:20 AM EST
Raja Priya Meganathan190 reputationPosted Mar 1, 2021, 9:00 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Mar 1, 2021, 9:32 AM EST
Ravi PatelRank #439 · 5.7K reputationPosted Mar 2, 2021, 2:07 AM EST