none
SmtpException: Failure sending mail. RRS feed

  • Question

  • I have a Visual Studio 2010 console application that targets the 3.5 framework that is receiving this error. (full error at bottom of message)

    The application generates reports from our database and emails them to users.  This works fine in most cases so I know the general connection information is correct however in a few cases this error occurs.  My best guess is that it has to do with the attachments being too large.  I am able to successfully send 7MB attachments but 12MB+ attachments seem to fail. (NOTE:  This does not have to do with the 4.0 framework bug because the app targets 3.5 and that particular bug wouldn't even allow the 7MB files as I understand it as the cap was around 4MB).

    On the ones that fail they generate the same error on my desktop and server even when being run all by themselves (so it doesn't appear to be a build up of resources that aren't being properly disposed.)

    My thought was that the mail server must be configured to not allow attachments over a certain size however my supervisor informed me that we have a classic ASP legacy app using a third party email plugin that's configured to use the exact same SMTP relay server and it regularly sends out files with 100+ MB attachments.  I'm at a loss on why this isn't working.  Any help would be greatly appreciated.

    Unhandled Exception: System.Net.Mail.SmtpException: Failure sending mail.
     ---> System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.
     ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
       at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
       at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32size)
       --- End of inner exception stack trace ---
       at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32size)
       at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Mime.SevenBitStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Mime.SevenBitStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Base64Stream.FlushInternal()
       at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Mime.MimePart.Send(BaseWriter writer)
       at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer)
       at System.Net.Mail.Message.Send(BaseWriter writer, Boolean sendEnvelope)
       at System.Net.Mail.MailMessage.Send(BaseWriter writer, Boolean sendEnvelope)
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       --- End of inner exception stack trace ---
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at QHExec.QHMail.Send(String toAddress, String subject, String name, Stream stream)
       at QHExec.QHWorker.Execute()
       at QHExec.Program.Main(String[] args)

    Tuesday, September 10, 2013 2:22 PM

Answers

  • Hi Nick,

    Welcome to MSDN forums.

    According to your description, you got an error in a few case when you are sending the emails.

    As you mentioned, it has to do with the attachments being too large. Maybe you are right.

    In my opinion, you can try to use the following steps to test it.

    l  For the exception, you can add try…catch… statement to enhance the robustness.

    l  You can try change the SmtpClient.Timeout Property larger if you use the SmtpClient object. An Int32 that specifies the time-out value in milliseconds. The default value is 100,000 (100 seconds). You can set the value of the property to 1500000(1500 seconds) or larger.

    From the error message, it is because the connection was closed by server side. I would suggest use Network Monitor to capture network traffic to check why the connection is closed by server side. And check if there is any firewall rules or third-party anti-virus software can block this.

    How to use Network Monitor to capture network traffic

    I understand you have a classic ASP legacy app that works when sending out mail with 100+M attachment, so I suggest you put your current app onto the same server which is hosting the ASP app and check if the issue still occurs.

    Please let me know if it works or not. Thanks.

    If you have any question, just feel free to let me know.

    Regards,

    Damon


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 11, 2013 8:48 AM
  • I resolved the problem by telnetting to the SMTP server and issuing the EHLO verb.  This revealed there was in fact a 10MB SIZE limit set on the server.   I presented this information to my supervisor who then attempted to send a larger then 10MB file to our development group from his classic asp app.  Needless to say it didn't work.  Apparently the add-in he's using for mail has been failing silently and no user has reported not getting their reports.  So in the end there was no issue with my application or .Net it, we just have a mail server constraint we were unaware of and the classic ASP app needs to be modified to handle it (mine already does).  Thank you for looking into this for me and I'm sorry for wasting your time.
    • Marked as answer by Damon Bu - MSFT Wednesday, September 18, 2013 1:03 AM
    Tuesday, September 17, 2013 2:14 PM

All replies

  • Hi Nick,

    Welcome to MSDN forums.

    According to your description, you got an error in a few case when you are sending the emails.

    As you mentioned, it has to do with the attachments being too large. Maybe you are right.

    In my opinion, you can try to use the following steps to test it.

    l  For the exception, you can add try…catch… statement to enhance the robustness.

    l  You can try change the SmtpClient.Timeout Property larger if you use the SmtpClient object. An Int32 that specifies the time-out value in milliseconds. The default value is 100,000 (100 seconds). You can set the value of the property to 1500000(1500 seconds) or larger.

    From the error message, it is because the connection was closed by server side. I would suggest use Network Monitor to capture network traffic to check why the connection is closed by server side. And check if there is any firewall rules or third-party anti-virus software can block this.

    How to use Network Monitor to capture network traffic

    I understand you have a classic ASP legacy app that works when sending out mail with 100+M attachment, so I suggest you put your current app onto the same server which is hosting the ASP app and check if the issue still occurs.

    Please let me know if it works or not. Thanks.

    If you have any question, just feel free to let me know.

    Regards,

    Damon


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 11, 2013 8:48 AM
  • I resolved the problem by telnetting to the SMTP server and issuing the EHLO verb.  This revealed there was in fact a 10MB SIZE limit set on the server.   I presented this information to my supervisor who then attempted to send a larger then 10MB file to our development group from his classic asp app.  Needless to say it didn't work.  Apparently the add-in he's using for mail has been failing silently and no user has reported not getting their reports.  So in the end there was no issue with my application or .Net it, we just have a mail server constraint we were unaware of and the classic ASP app needs to be modified to handle it (mine already does).  Thank you for looking into this for me and I'm sorry for wasting your time.
    • Marked as answer by Damon Bu - MSFT Wednesday, September 18, 2013 1:03 AM
    Tuesday, September 17, 2013 2:14 PM