C# send email using gmail smtp Edit

Murugan Andezuthu Dharmaratnam | 11 September 2020 | 66

In C# .net use can use the SmtpClient in System.Net.Mail namespace to send mail using SMTP.

Gmail SMTP settings

Server Address: smtp.gmail.com
Username: Your Gmail Email Address (e.g. yourmail@gmail.com)
Password: Your Gmail Password
Port Number: 587 (With TLS)

C# code to send mail using SMTP

 MailMessage MailMessage = new MailMessage();
 MailMessage.From = new MailAddress("yourmail@gmail.com");
 MailMessage.Subject = "SMTP test mail";
 MailMessage.Body = "Hello Mail Message";
 SmtpClient SmtpClient = new SmtpClient();
 SmtpClient.Host = "smtp.gmail.com";
 SmtpClient.EnableSsl = false;
 SmtpClient.Port = 587;
 SmtpClient.Credentials = new System.Net.NetworkCredential("yourmail@gmail.com", "yourpassword");
 }catch(Exception ex)
     throw ex;

check this article "gmail SMTP mail The SMTP server requires a secure connection or the client was not authenticated" if you are finding errors while sending mail.