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.