Invia solo un singolo MailMessage da una connessione. In realtà, non chiude nemmeno correttamente la connessione. Invia la posta, ma poi non dice al server di posta che vuole uscire. Quindi, lo lascia semplicemente sospeso, finché il flusso di pool sottostante decide di chiudere il socket.
Ecco il codice interno da riflettore:
...
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);
}
btw, qui è più informazioni sul SmtpClient non emettendo il comando QUIT. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=146711&wa=wsignin1.0
Edit: visualizzare il link morto sopra il web.archive.org
Il work-around è quello di impostare SmtpClient.ServicePoint.MaxTimeout a 1. Questo chiuderà la presa più veloce, tuttavia, questo in realtà non emette il Comando QUIT.
fonte
2009-06-09 12:41:51
Il problema relativo a 'QUIT' è stato risolto nei nuovi framework .NET? – jocull
Questo è stato apparentemente risolto in. NET 4.0 https://stackoverflow.com/questions/1466572/net-system-net-mail-smtpclient-class-doesnt-issue-quit-command-to-smtp-transac?noredirect=1 # comment79406662_1466572 – jocull