A little background. Our ASP.NET website sends emails when forms are submitted. The current code looks like this:

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)
End Sub

Intermittently, it gets the following response from the SMTP server:

Service not available, closing transmission channel. The server response was: 4.3.2 Service not active

Doing some research on that error, leads me to believe it's because the SMTP server doesn't like you for some reason. So I started looking at configuring the SmtpClient to see if it was correct in the code. What I found was this from a Microsoft web site:

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.

So I thought maybe too many connections left open during heavy usage of the page? Maybe I should call the Dispose method, or encapsulate in a Using block. But the phrase that stuck out at me was this one:

all established connections to the SMTP server

It doesn't say anything about the same process, page instance, or whatever. Just that ALL established connections will be terminated.

So what I want to know is, if person1 and person2 are submitting a page at the same time, could calling the dispose method from person1 potentially close the SMTP connection for person2 before that email gets sent?

Related posts

Recent Viewed