The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
try
{
    MailMessage mail = new MailMessage();
    string to = "dattatray96@gmail.com";
    mail.To.Add(to);
    mail.From = new MailAddress("dattatray96@gmail.com");
    mail.Subject = "Mail";
    mail.Body = " HI";
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
    smtp.EnableSsl = true;
    smtp.Send(mail);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message); Console.ReadLine();
}
 
     
    