System.Net.Mail.SmtpException: Failure sending mail.


  • Hello,

    I am writing an ASP.NET application that automatically generates email messages.
    My issue is that it works sporadically: sometimes email messages go out, and sometimes they don't.
    My suspicion is that my messages don't go out sporadically due to my application being unable to establish connection to my smtp server.

    Does anybody how to first establist connection to SMTP server, and when connection is establish, then to attempt sending email message by using VB.NET?
    Thank you in advance.

    Here is the error message I get when sending email fails:

    System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at BSR.SubmitBSR.SendEmail() in D:\Projects\BSR\SubmitBSR.aspx.vb:line 564

    Here is my line of code that creates a message and tries to send it out:

    MailHelper.SendMailMessage("", "", "", "", "Subject of the message", "Body of the message")

    Here is the class I am using to instantiate email:






    Class MailHelper


    ''' <summary>


    ''' Sends an mail message


    ''' </summary>


    ''' <param name="from">Sender address</param>


    ''' <param name="recepient">Recepient address</param>


    ''' <param name="bcc">Bcc recepient</param>


    ''' <param name="cc">Cc recepient</param>


    ''' <param name="subject">Subject of mail message</param>


    ''' <param name="body">Body of mail message</param>


    Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, _


    ByVal subject As String, ByVal body As String)


    ' Instantiate a new instance of MailMessage


    Dim mMailMessage As New MailMessage()


    ' Set the sender address of the mail message

    mMailMessage.From =

    New MailAddress(from)


    ' Set the recepient address of the mail message


    New MailAddress(recepient))


    ' Check if the bcc value is null or an empty string


    If Not bcc Is Nothing And bcc <> String.Empty Then


    ' Set the Bcc address of the mail message


    New MailAddress(bcc))


    End If


    ' Check if the cc value is null or an empty value


    If Not cc Is Nothing And cc <> String.Empty Then


    ' Set the CC address of the mail message


    Dim splitCC() As String = cc.Split(";"c)


    For Each s As String In splitCC





    End If


    ' Set the subject of the mail message

    mMailMessage.Subject = subject


    ' Set the body of the mail message

    mMailMessage.Body = body


    ' Secify the format of the body as HTML

    mMailMessage.IsBodyHtml =



    ' Set the priority of the mail message to normal

    mMailMessage.Priority = MailPriority.Normal


    ' Instantiate a new instance of SmtpClient


    Dim mSmtpClient As New SmtpClient()


    ' Send the mail message



    End Sub




    Saturday, August 22, 2009 2:40 AM


All replies

  • The server closed the connection unexpectedly.  Find a better server.

    Hans Passant.
    Saturday, August 22, 2009 11:59 AM
  • Hi YmaZur,

    if your smtp server is a microsoft exchange server then The smtpclient.send method is closely linked with the microsoft exchange internet mail service. if the service is down you will surely get this exception thrown from your application. so it will help if you can ask you Exchange server administrator to restart this service which should do the trick. of course this is valid only if your smtp server is not a remote server.

    hope this helps!! 

    Thursday, March 11, 2010 11:54 AM