I have a ASP.net Web Forms Application using .net framework v4.0 hosted on the intranet of my organisation
Recently the app stopped sending emails
here is the code
public void SendMail(string host, string userid, string password, string to, string from, string cc, string bcc, string subject, string body)
{
try
{
if (from.Equals("") == false && to.Equals("") == false)
{
MailAddress mfrom = new MailAddress(from);
MailAddress mto = new MailAddress(to);
MailMessage mail = new MailMessage(mfrom, mto);
if (cc.Equals("") == false)
{
MailAddress mcc = new MailAddress(cc);
mail.CC.Add(mcc);
}
if (bcc.Equals("") == false)
{
MailAddress mbcc = new MailAddress(bcc);
mail.Bcc.Add(mbcc);
}
SmtpClient client = new SmtpClient();
client.Host = host;
client.Port = int.Parse(WebConfigurationManager.AppSettings["MailPort"]);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(userid, password);
client.Credentials = credentials;
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
client.TargetName = "STARTTLS/smtp.office365.com";
client.Send(mail);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
<appSettings>
<add key="MailHostName" value="smtp.office365.com"/>-->
<add key="MailSenderName" value="email@organisation.com"/>
<add key="MailSenderPwd" value="mAilPa55w0rd"/>
<add key="MailPort" value="587"/>
<appSettings>
I get this message "Failure Sending Mail"
Unable to read data from the transport connection: net_io_connectionclosed.
What I have tried:
I have re-configured the app to use .Net Framework 4.8
I have added the app to the IIS Manager using a Self Signed Certificate using the https protocol
I have imported the Self Signed Certificate in the CertManager on the server
The App runs fine using https on IIS Server but only the mails are not delivered.