0

I have a windows application desktop-based(C#) developed long days ago by Microsoft Visual Studio 2008. This application used SmtpClient for system-generated email services. smtp.office365.com email service used for from email address. It's working very well but recently shown an exception.

Unable to read data from the transport connection: net_io_connectionclosed.

I am trying to solve it for a few days but not possible.

Code:

  dt_email = dh.select_table("Select * from dbo.tblEmailInfo");
                    try
                    {
                        MailMessage mM = new MailMessage();
                        mM.From = new MailAddress(dt_email.Rows[0][1].ToString());

                        mM.To.Add(this.dgvAction.CurrentRow.Cells[23].Value.ToString());
                      
                        mM.CC.Add(dt_email.Rows[0][1].ToString());
                                             

                        mM.Subject = "Leave Adjustment";

                        mM.Body = get_boy(e.RowIndex, adjust, dt_email.Rows[0][4].ToString(), remarks);

                        mM.IsBodyHtml = true;
                                               
                        SmtpClient SmtpServer = new SmtpClient();

                        SmtpServer.Credentials = new System.Net.NetworkCredential(dt_email.Rows[0][1].ToString(), dt_email.Rows[0][2].ToString());//Provide yoyr gmail credentials email and password

                        SmtpServer.Port = 587;
                       
                        SmtpServer.EnableSsl = true;
                                                
                        SmtpServer.Host = dt_email.Rows[0][3].ToString();

                        SmtpServer.Send(mM);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }


                    MessageBox.Show("Email Notification has been successfully sent.");

How to solve this exception.

enter image description here

Malay Roy
  • 77
  • 2
  • 6
  • Here is a long running post with the same error. There are several answers from people with similar configurations to yours. You may find an answer here: https://stackoverflow.com/a/53116578/2069745 – Pynt May 27 '22 at 16:05
  • Does this answer your question? [SmtpException: Unable to read data from the transport connection: net\_io\_connectionclosed](https://stackoverflow.com/questions/20228644/smtpexception-unable-to-read-data-from-the-transport-connection-net-io-connect) – pringi May 29 '22 at 09:51

1 Answers1

0

I've had the exact same issue, you need to put this in the beginning:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
peterkodermac
  • 318
  • 5
  • 13