Failure sending mail. Unable to write data to the transport connection

10,390

Solution 1

I was experiencing this same issue recently with SmtpClient.SendMail(MailMessage) being used repeatedly with an email with a 350k attachment. Every 33rd message, the error you gave would occur.

Turns out our shared component which encapsulated the SendMail functionality was not calling Dispose() on the SmtpClient class when the message was finished sending.

Adding client.Dispose() to the SmtpClient instance cleared the problem right up and now messages go out no problem - hundreds of them (and yes they're legitimate product notifications to our customers, not spam) ;)

Solution 2

From what I read on the net, the Winsock error code associated with this exception is WSAECONNABORTED.

You can read more about it at this address for an explanation: WSAECONNABORTED

Basically it means that the server closed the connection while your application was trying to send a large e-mail.

Maybe you should check the Gmail documentation to see if it has some limitation on message size, or total number of messages sent. Looks like you're pumping too much data on the socket.

Share:
10,390
Uma
Author by

Uma

Updated on July 22, 2022

Comments

  • Uma
    Uma almost 2 years

    I am using a Gmail SMTP server to send mail from VB.Net. Although it sends some emails fine, for some others it returns the following error:

    Failure sending mail. Unable to write data to the transport connection System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine

  • Michael
    Michael about 10 years
    Sounds like time for a using block. ;-)
  • Can Sahin
    Can Sahin about 7 years
    Even though TheEvilGreebo's answer contained the answer to my problem, your answer ensured that this Q&A popped up in Google when I was searching for SmtpClient and WASECONNABORTED. So... thanks for your answer as well. :-)
  • Bonez024
    Bonez024 almost 4 years
    Where exactly did you do that?