【问题标题】:Unable to read data from the transport connection: net_io_connectionclosed smtp.office365.com无法从传输连接读取数据:net_io_connectionclosed smtp.office365.com
【发布时间】:2022-08-19 15:57:07
【问题描述】:

我有一个很久以前由 Microsoft Visual Studio 2008 开发的基于桌面的 Windows 应用程序(C#)。这个应用程序使用 SmtpClient 来提供系统生成的电子邮件服务。用于来自电子邮件地址的 smtp.office365.com 电子邮件服务。它工作得很好,但最近出现了异常。

无法从传输连接读取数据:net_io_connectionclosed。

我试图解决它几天但不可能。

代码:

  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.\");

如何解决这个异常。

标签: c# .net office365 smtpclient


【解决方案1】:

我遇到了完全相同的问题,您需要将其放在开头:

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

【讨论】:

    猜你喜欢
    • 2016-02-21
    • 2013-12-12
    • 2013-07-04
    • 1970-01-01
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多