不知道为什么会这样。我搜索过的每一个地方都告诉我我做对了。但是每次我尝试发送邮件时,它都会超时smtpserver.Send(mail)
private void emailReport(string email_address,int begDatabaseCount, int endDatabaseCount)
{
SmtpClient smtpserver = new SmtpClient();
MailMessage mail = new MailMessage();
smtpserver.EnableSsl = true;
smtpserver.Port = 465;
smtpserver.Host = "smtp.gmail.com";
smtpserver.Credentials = new NetworkCredential("mtaylor@atr.com", "password");
smtpserver.UseDefaultCredentials = false;
mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("mtaylor@atr.com", "ATR Reports");
mail.To.Add(email_address);
mail.Subject = "FNAS Report - " + DateTime.Now;
mail.Body += "<u><b>FNAS Report for " + DateTime.Now + "</u></b>" + "\r\n \r\n";
mail.Body += "Beginning Database Count - " + begDatabaseCount + "\r\n" + "\r\n";
mail.Body += "End Database Count - " + endDatabaseCount + "\r\n" + "\r\n";
mail.Body += "<b>Total Imported Orders = " + (endDatabaseCount - begDatabaseCount) + "<b>" + "\r\n" + "\r\n";
mail.IsBodyHtml = true;
smtpserver.Send(mail);
}
端口 465 = 1 分钟后超时
端口 587 = “SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。”