Try using below code along with above answer: var smtpClient = new SmtpClient("smtp.gmail.com") { Port = 587,Credentials = new NetworkCredential("gmail emailid", "App Password"), EnableSsl = true,};