SmtpClient - 调用 dispose 是否只关闭它创建的连接?还是微软似乎表示的所有连接?
SmtpClient - Does calling dispose close only the connection it created? Or all connections as Microsoft seems to indicate?
一点背景。我们的 ASP.NET 网站会在提交表单时发送电子邮件。当前代码如下所示:
Sub SendEmail(ByVal ToList As String, ByVal Subject As String, ByVal HTMLBody As String)
Dim Message As New Mail.MailMessage("someone@company.com", ToList)
Message.Subject = Subject
Message.Body = HTMLBody
Message.IsBodyHtml = True
Dim smtp As New SmtpClient("smtp.servername.com", 25)
smtp.Send(Message)
End Sub
间歇性地,它从 SMTP 服务器收到以下响应:
Service not available, closing transmission channel. The server
response was: 4.3.2 Service not active
对该错误进行一些研究后,我相信这是因为 SMTP 服务器出于某种原因不喜欢您。所以我开始查看配置 SmtpClient 以查看它在代码中是否正确。我从 Microsoft 网站 this 找到的内容:
The SmtpClient class has no Finalize method, so an application must
call Dispose to explicitly free up resources. The Dispose method
iterates through all established connections to the SMTP server
specified in the Host property and sends a QUIT message followed by
gracefully ending the TCP connection.
所以我认为在大量使用页面期间可能有太多连接保持打开状态?也许我应该调用 Dispose 方法,或者封装在 Using 块中。但让我印象深刻的是这句话:
all established connections to the SMTP server
它没有说明相同进程、页面实例或其他任何内容。只是所有已建立的连接都将终止。
所以我想知道的是,如果 person1 和 person2 同时提交页面,从 person1 调用 dispose 方法是否可能在发送电子邮件的过程中关闭 person2 的 SMTP 连接?
来自文档 https://msdn.microsoft.com/en-us/library/ee706941(v=vs.110).aspx:
Sends a QUIT message to the SMTP server, gracefully ends the TCP
connection, and releases all resources used by the current
instance of the SmtpClient class.
person1 和 person2 将有自己的实例,这样他们就不会相互影响。
一点背景。我们的 ASP.NET 网站会在提交表单时发送电子邮件。当前代码如下所示:
Sub SendEmail(ByVal ToList As String, ByVal Subject As String, ByVal HTMLBody As String)
Dim Message As New Mail.MailMessage("someone@company.com", ToList)
Message.Subject = Subject
Message.Body = HTMLBody
Message.IsBodyHtml = True
Dim smtp As New SmtpClient("smtp.servername.com", 25)
smtp.Send(Message)
End Sub
间歇性地,它从 SMTP 服务器收到以下响应:
Service not available, closing transmission channel. The server response was: 4.3.2 Service not active
对该错误进行一些研究后,我相信这是因为 SMTP 服务器出于某种原因不喜欢您。所以我开始查看配置 SmtpClient 以查看它在代码中是否正确。我从 Microsoft 网站 this 找到的内容:
The SmtpClient class has no Finalize method, so an application must call Dispose to explicitly free up resources. The Dispose method iterates through all established connections to the SMTP server specified in the Host property and sends a QUIT message followed by gracefully ending the TCP connection.
所以我认为在大量使用页面期间可能有太多连接保持打开状态?也许我应该调用 Dispose 方法,或者封装在 Using 块中。但让我印象深刻的是这句话:
all established connections to the SMTP server
它没有说明相同进程、页面实例或其他任何内容。只是所有已建立的连接都将终止。
所以我想知道的是,如果 person1 和 person2 同时提交页面,从 person1 调用 dispose 方法是否可能在发送电子邮件的过程中关闭 person2 的 SMTP 连接?
来自文档 https://msdn.microsoft.com/en-us/library/ee706941(v=vs.110).aspx:
Sends a QUIT message to the SMTP server, gracefully ends the TCP connection, and releases all resources used by the current instance of the SmtpClient class.
person1 和 person2 将有自己的实例,这样他们就不会相互影响。