它只從連接發送一個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