+1 vote

We are trying to send a message with a single PDF attachment but it always fails. This is not happening with other PDF attachments.

The size of the attachment is:
1,906,061 bytes

We have increased send timeout to 900 seconds:
smtp.SendTimeout = new TimeSpan(0, 0, 900);

The MimeData.ContentType used for the attachment is "application/pdf" - as we use byte array and not file we have to set the Content Type manually using ContentType.Parse("application/pdf").

The error we get is:
Limilabs.Client.ServerException: Tried to read a line. Only '' received. Please make sure that antivirus and firewall software are disabled or configured correctly. ---> System.Exception: Tried to read a line. Only '' received. ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
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)

We have tried 2 different SMTP Servers and problem persists.

Can you help us with this please?

Regards,

Manolis

by (1.2k points)
edited by
In Addition: Although we set smtp.SendTimeout the problem seems to come 30 seconds after calling smtp.SendMessage(msg);

1 Answer

0 votes
 
Best answer
  1. The problem is with reading data (StackTrace: NetworkStream.Read),
    not with sending, so you should increase ReceiveTimeout property.

  2. Use ContentType.ApplicationPdf (instead of ContentType.Parse method).

  3. 1.9 MB pdf file results in over 2.5 MB email (due to Base64 encoding), are you sure you're not hitting SMTP server limit? Server may be disconnecting in such case.

  4. Consider turning on Mail.dll logging and examine the logs.

  5. Make sure you have turned off (or configured correctly) all firewall/antivirus software. This includes Window Defender.

If your server supports SIZE extension you can check the maximum sizeof the message you can send in bytes:

 SmtpSizeExtension size = (SmtpSizeExtension) 
      smtp.SupportedExtensions().Find(x => x is SmtpSizeExtension);
 long size = size.Value;
by (301k points)
selected by
I tried to set
smtp.ReceiveTimeout = new TimeSpan(0, 0, 900); // 900 seconds

This was enough - everything worked fine!

Note: I didn't think to increase ReceiveTimeout as I was using SMTP for sending only. But SMTP  protocol, on socket level, uses both read and write and these timeouts were socket level timeouts.

Thank you for your excellent assistance!

Manolis
...