我不确定为什么会发生这种情况。我在搜索的所有地方都告诉我我做得对。但每次我尝试发送邮件时,它都会在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需要验证身份。"