0

I am getting the error "Unable to read data from the transport connection" when sending an email using the SmtpClient. The error does not happen when I am running this in Visual Studio. The error only happens when it is running in IIS. Below is my code:

            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);

            SmtpClient SmtpServer = new SmtpClient(_serviceSettings.SMTPServer, _serviceSettings.SMTPPort);
            SmtpServer.Port = _serviceSettings.SMTPPort;
            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Credentials = new System.Net.NetworkCredential(_serviceSettings.SMTPUser, _serviceSettings.SMTPPass);


            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(_serviceSettings.SMTPUser);
            mail.To.Add(_serviceSettings.SMTPErrorTo);
            mail.Subject = "Error Message";
            mail.Body = errorMessage;

            SmtpServer.EnableSsl = _serviceSettings.SMTPUseSSL;

            SmtpServer.Send(mail);
Andy
  • 43
  • 4
  • You can try the method mentioned in this link: https://stackoverflow.com/questions/17497154/smtpexception-unable-to-read-data-from-the-transport-connection-net-io-connec – JennyDai May 13 '22 at 03:10

1 Answers1

0

It ended up being an issue with the SMTP server. One of the email servers in the cluster was having an issue.

Andy
  • 43
  • 4