我的Web服务正在将电子邮件发送到IISv6 localhost邮件中继,但是随机出现“超时等待客户端输入”错误。我们在数据中心中有几个虚拟机,它们以相同的方式进行设置,并且它们都会不时出现此问题,因此我认为这与硬件无关。我在SmtpClient.Send randomly causes SmtpException 4.7.0 timeout waiting for client input读过类似的问题,但根据发布者的结论,结论似乎与交换服务器身份验证有关。因为我正在将电子邮件发送到localhost中继,所以我不认为会有这个问题。我的代码没什么特别的
MailMessage message = new MailMessage();
message.From = new MailAddress(from);
foreach (string address in receivers)
{
message.To.Add(address);
}
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = server;
smtpClient.Port = port;
smtpClient.EnableSsl = ssl_enabled;
if (username != "")
{
smtpClient.Credentials = new System.Net.NetworkCredential(username, password, domain);
}
smtpClient.Timeout = email_timeout;
try
{
smtpClient.Send(message);
email_retry_attempts = 0;
message.Dispose();
}
catch (Exception e)
{
Log.Exception(e, e.Message);
}
finally
{
// Try and close up the connections
smtpClient.Dispose();
smtpClient.ServicePoint.CloseConnectionGroup("");
smtpClient.ServicePoint.CloseConnectionGroup(smtpClient.ServicePoint.ConnectionName);
email_retry_attempts--;
}