“Unable to read data from the transport connection: net_io_connectionclosed.” - Windows Vista Business and SMTP

后端 未结 11 1775
北海茫月
北海茫月 2021-02-06 21:37

Unable to test sending email from .NET code in Windows Vista Business.

I am writing code which I will migrate to an SSIS Package once it its proven. The code is to send

11条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 22:31

    I developed a Windows Service application in VB using .NET Framework v4.5 and recently ran into this issue.

    First, a little background - I ran into the OP's error after trying to deal with the error "Service not available, closing transmission channel. The server response was: Error: too many messages in one session" which was resolved by calling the Dispose method on the SmtpClient object after each email sent. Just to be ultra safe, I also called Dispose on the MailMessage object.

    Okay, so now the 'too many messages in one session' issue is resolved but now I occasionally got the 'Unable to read data from the transport connection: net_io_connectionclosed' error. Awesome. Turns out I had not implemented my email class consistently - in one instance, it was being disposed of while in the other it was not.

    Here's an example of what resolved both issues for me (it's in VB but you get the idea):

    With New clsEmail(True)
        With .Message
            .To.Add("user@domain.com")
            .Subject = msgSubject
            .Body = msgContents
        End With
    
        .Server.Send(.Message)
        .Server.Dispose()
        .Message.Dispose()
    End With
    

    My email class has, among other things, has 2 properties - Message (System.Net.Mail.MailMessage) and Server (System.Net.Mail.SmtpClient) which is what's being disposed in this example.

    I haven't had a single problem after hundreds of emails once every single instance that sends email in my service was implemented in this way.

提交回复
热议问题