smtpclient.send RRS feed

  • Question

  • The following code was working correctly for over a year. Upgraded to new .net framework and smtpclient.send no longer works and throws an exception. here is the test code:

        Protected Sub Submit_Click(sender As Object, e As System.EventArgs)

            Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
            mailMessage.From = New       System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings("fromEmail"))
            mailMessage.Subject = System.Configuration.ConfigurationManager.AppSettings("EmailSubject")

            mailMessage.Body = mailMessage.Body & "Food Lot Tracking" & Environment.NewLine

            mailMessage.IsBodyHtml = False

            Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()

            Catch ex As Exception
            End Try


        End Sub

    Thanks in advance for your help.


    Thursday, October 10, 2019 8:09 PM

All replies

  • Hi

    Do you not think that it could be helpful to tell us what the exception message was?

    Also, for ease of use:

    Regards Les, Livingston, Scotland

    Thursday, October 10, 2019 8:33 PM
  • Thanks for your reply! The following is the error as well as the stack Trace. Additionally the code worked in .net framework 4.5 but stopped when we updated to .net 4.8. Thanks again!

    Server Error in '/' Application.

    Unable to read data from the transport connection: net_io_connectionclosed.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.

    Source Error:
    Line 26: 
    Line 27:         Try
    Line 28:             smtpClient.Send(mailMessage)
    Line 29: 
    Line 30:         Finally

    Source File: C:\SafeFoodSoftware\EmailTest.aspx.vb    Line: 28

    Stack Trace:
    [IOException: Unable to read data from the transport connection: net_io_connectionclosed.]
       System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) +704
       System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +297
       System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +25
       System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) +70
       System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) +42
       System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) +119
       System.Net.Mail.SmtpClient.Send(MailMessage message) +2279
    [SmtpException: Failure sending mail.]
       System.Net.Mail.SmtpClient.Send(MailMessage message) +3250
       EmailTest.Submit_Click(Object sender, EventArgs e) in C:\SafeFoodSoftware\EmailTest.aspx.vb:28
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11596844
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +274
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1964

    Thursday, October 10, 2019 9:49 PM
  • Hi

    Thanks for the details.

    I can't determine anything helpful. Maybe someone else can assist.

    Have tou used a Break Point to examine the full contents of mailMessage to verify that they are as expected and not malformed?

    Regards Les, Livingston, Scotland

    Thursday, October 10, 2019 10:28 PM
  • Thanks again! Reading that microsoft doesn't support smtpclient.send anymore (ver 4.8 framework) and people are saying to use mailkit but I don't see a way to use this with microsoft web developer. We don't use visual studio.
    Friday, October 11, 2019 12:20 AM
  • If you are writing VB.NET (or C#) code then MailKit is usable. The Smtp method was okay yet MailKit is much better.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Friday, October 11, 2019 1:10 AM