2

The first email is getting successfully sent and others are getting error.

Stack Trace -

 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.SmtpConnection.GetConnection(ServicePoint servicePoint)
       at System.Net.Mail.SmtpClient.Send(MailMessage message)

Please help me to resolve this problem.

This my code.

SmtpClient SmtpServer = new SmtpClient(System.Configuration.ConfigurationSettings.AppSettings["SMTP_server"]);
                                    //email port
                                    SmtpServer.Port = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["SMTP_Port"]);
                                    //mail server credentials
                                    var userName = System.Configuration.ConfigurationSettings.AppSettings["NetworkCredential_userName"];
                                    var password = System.Configuration.ConfigurationSettings.AppSettings["NetworkCredential_Password"];
                                    if (userName.Length == 0 && password.Length == 0)
                                    {
                                        SmtpServer.Credentials = new System.Net.NetworkCredential();
                                    }
                                    else
                                    {
                                        SmtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
                                    }
                                    //ssl availablility
                                    SmtpServer.EnableSsl = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableSsl"]);
                                    mail.Priority = MailPriority.High;
                                    SmtpServer.Send(mail);
                                    //disposing attachment after sending
                                    attachment.Dispose();
                                    SmtpServer.Dispose();
Ranga
  • 258
  • 2
  • 13
  • Looks like your connection is closed... Any code? – yu_ominae Mar 11 '15 at 10:59
  • I only see you sending one email in there. Is that the full code? Is the error occurring after you dispose of the SMTPServer? By the way, why are you disposing of it if you have more than one email to send? – yu_ominae Mar 11 '15 at 11:08
  • nope.. I'm defining the message and simple passed it into the smtp server. – Ranga Mar 11 '15 at 11:14
  • Just wondering if you already saw this: http://stackoverflow.com/questions/17497154/smtpexception-unable-to-read-data-from-the-transport-connection-net-io-connec? – yu_ominae Mar 11 '15 at 11:20
  • it didn't help me.This was worked well until today. – Ranga Mar 11 '15 at 17:58

2 Answers2

1

This causes because of the remote SMTP server firewall rules.The server rules are changed suddenly and it affects my code. Actually what I did was sleep time of my thread increased and it started working fine.

Ranga
  • 258
  • 2
  • 13
0

Try below but only fr local machine, should not be the case for Production envrionement-

In host file point the 127.0.0.1 to your machine name and

In code -

var client = new SmtpClient("local machine name")
client.Send(mail)
CHash11
  • 746
  • 4
  • 14
  • 31
  • This is on Production envrionement :( – Ranga Mar 11 '15 at 12:19
  • sometimes its dependent on the internet connection, considering this is on production environment, internet connection wont be the private connection!! I would suggest to check whether the your SMTP server is reachable over given port!! Try adding below setting - Client.ServicePoint.MaxIdleTime = 2; – CHash11 Mar 11 '15 at 16:07