接続から単一の MailMessage のみを送信します。実際、接続を適切に閉じることさえできません。メールを送信しますが、終了したいことをメールサーバーに伝えません。そのため、基になるプールされたストリームがソケットを閉じることを決定するまで、開いたままにしておくだけです。
Reflector の内部コードは次のとおりです。
...
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 コマンドは発行されません。