它只从连接发送一个MailMessage。实际上,它甚至没有正确关闭连接。它发送邮件,但它不告诉邮件服务器它要退出。所以,它只是让它悬空,直到底层合并流决定关闭套接字。
下面是从反射器的内部代码:
...
this.GetConnection();
fileMailWriter = this.transport.SendMail((message.Sender != null) ? message.Sender : message.From, recipients, message.BuildDeliveryStatusNotificationString(), out exception);
}
catch (Exception exception2)
{
if (Logging.On)
{
Logging.Exception(Logging.Web, this, "Send", exception2);
}
if ((exception2 is SmtpFailedRecipientException) && !((SmtpFailedRecipientException) exception2).fatal)
{
throw;
}
this.Abort();
if (this.timedOut)
{
throw new SmtpException(SR.GetString("net_timeout"));
}
if (((exception2 is SecurityException) || (exception2 is AuthenticationException)) || (exception2 is SmtpException))
{
throw;
}
throw new SmtpException(SR.GetString("SmtpSendMailFailure"), exception2);
}
顺便说一句,这里有更多关于该SmtpClient不发出QUIT命令。 https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=146711&wa=wsignin1.0
编辑:...查看web.archive.org
以上的死链接的解决办法是,以SmtpClient.ServicePoint.MaxTimeout设置为1,这将关闭套接字更快,但是,这实际上并没有发出QUIT命令。
QUIT是否已经在更新的.NET框架中解决了问题? – jocull 2017-09-14 14:34:18