简体   繁体   中英

Unable to read data from the transport connection: net_io_connectionclosed smtp.office365.com

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.

在此处输入图像描述

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

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM