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"