The server is spinning a service that sends mail according to certain events. Faced the following error:

[14.09.2017 15:10:00.971] [System.Net.Mail.SmtpClient.Send()] System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at WindowsServiceWeather.Email.sendEmail(String mess, String theme) 

I made an imitation of sending to the button, on my PC it works normally, on the server, when I first click, the described error comes out, with the second one it sends and the subsequent presses are also sent normally. I noticed that after some time without action on the server, in spite of the RDP, if you click again, the same error will come out and again, subsequent clicks will still send letters. Here is the code:

  IniFile INI = new IniFile(); string fromEmailUser = INI.ReadINI("EmailSetting", "fromEmailUser"); string emails = INI.ReadINI("EmailSetting", "emails"); string smtpString = INI.ReadINI("EmailSetting", "smtpString"); int smtpPort = int.Parse(INI.ReadINI("EmailSetting", "smtpPort")); string mailUser = INI.ReadINI("EmailSetting", "mailUser"); string mailUserPassword = INI.ReadINI("EmailSetting", "mailUserPassword"); // отправитель - устанавливаем адрес и отображаемое в письме имя MailAddress from = new MailAddress(fromEmailUser, "Скрипт погоды"); // создаем объект сообщения using (MailMessage m = new MailMessage()) { m.From = from; string[] adrs = emails.Split(';'); foreach (string adr in adrs) { m.To.Add(adr); } // тема письма m.Subject = theme; // текст письма m.Body = mess; // письмо представляет код html m.IsBodyHtml = true; // адрес smtp-сервера и порт, с которого будем отправлять письмо SmtpClient smtp = new SmtpClient(smtpString, smtpPort); // логин и пароль smtp.Credentials = new NetworkCredential(mailUser, mailUserPassword); smtp.EnableSsl = true; smtp.Send(m); 
  • one
    Is this your mailer and can you show it to / var / log / maillog or get a crystal ball? Honestly: I don’t see how to help. Well, you closed the connection, but why and how - purely guessing is only possible with the amount of information provided. For some reason, it also seems to me that a Unix sendmail is an inappropriate label to the question, but anything happens in the modern heterogeneous world ... - AK
  • @AK I did not even know that the label is related to anything, I thought it was just a tag. In the logs there is nothing in those moments when I imitate an error. - Winteriscoming

0