SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。
了解更多信息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();
}
答案 0 :(得分:2)