Avatar of Tammu

asked on 

Unable to read data from the transport connection : net_io_connectionclosed

Hello Experts,
i have a mail server for my web site ( mail.Mysite.com) . it used to work fine. since last week i am getting an error whenever i am trying to send emails or even bring in orders from online in batches ( NOT ALWAYS , ITS HAPPENING ON RANDOM BASIS) i am attaching the screenshot of the error.

i have contacted my web hosting company. and they told me to change the some lines of code in the related file called orders.aspx. i am posting the suggestions given by them aslo. but my question is how come all of sudden its not working  and if i do change the code how they suggested, what will be outcome.

i always trusted experts  suggestions at experts-exchange.com. so please kindly advice me. i appreciate it.

First: the error : look the screenshot please

Code involved in orders.aspx: see the code attached

suggestions made by hosting company:
Given the intermittent problems this is the suggestion I have in order to solve the issue.

First, We noticed that you are setting up a delivery method on line 149 which is not needed:

MailRelay.DeliveryMethod = SmtpDeliveryMethod.Network;

We also see that you are using Default Credentials on the next line (150):

MailRelay.UseDefaultCredentials = true;

We recommend that you use SMTP Authenticatio instead, and replace the line above with something line this:

MailRelay.Credentials = new System.Net.NetworkCredential("valid_email_address@MySite.com", "<VALID_PASSWORD>");

Finally, add a catch statement after line 174 that attempts different SMTP servers. On your catch statement, try to resend the message using the following SMTP Servers:


You are more than welcome to have your catch statement first try mail42.safesecureweb.com . If at the final step it fails, then throw the exception or handle the error as you would like.

Can someone please help me out in this regard. I am stuck . Thanks once again Experts

private void emailOrders( string fileName, int batchId )
        FileStream AttachmentStream = new FileStream(
            FileAccess.Read );
            SmtpClient MailRelay = new SmtpClient(
                ConfigurationManager.AppSettings[ "SmtpRelay" ] );
            MailRelay.DeliveryMethod = SmtpDeliveryMethod.Network;
            MailRelay.UseDefaultCredentials = true;
            MailMessage OrdersEmail = new MailMessage( );
            OrdersEmail.To.Add( ConfigurationManager.AppSettings[ "OrdersEmailRecipient" ] );
            OrdersEmail.From = new MailAddress( ConfigurationManager.AppSettings[ "OrdersEmailRecipient" ] );
            OrdersEmail.Subject = string.Format( "Batch: {0}", batchId );
            ContentType AttachmentType = new ContentType( );
            AttachmentType.MediaType = "application/octet-stream";
            Attachment OrdersAttachment = new Attachment( AttachmentStream, AttachmentType );
            OrdersAttachment.ContentDisposition.FileName = string.Format(
                batchId );
            OrdersAttachment.ContentDisposition.DispositionType = "attachment";
            OrdersAttachment.TransferEncoding = TransferEncoding.Base64;
            OrdersEmail.Attachments.Add( OrdersAttachment );
            OrdersEmail.IsBodyHtml = false;
            MailRelay.Send( OrdersEmail );
            AttachmentStream.Close( );

Open in new window

Email Protocols.NET ProgrammingASP.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon