Connecting to SMTP server takes long time (15s)

We have been using Aspose.Email succesfully for a long time connecting to several smtp services but now we are encountering very long connect times (over 15 seconds) with a specific server. After the first connect, emails are send quickly. Currently we are using Aspose.Email 21.4.0.0 with this code:

smtpClient = new SmtpClient(_mailConfiguration.SmtpServer, _mailConfiguration.SmtpPort, SecurityOptions.SSLExplicit);
smtpClient.HelloMessage = _mailConfiguration.SenderDomain;
smtpClient.AllowedAuthentication = Aspose.Email.Clients.Smtp.SmtpKnownAuthenticationType.Anonymous;
await smtpClient.SendAsync(mailMessage);

This is the log file of the smtp client:

-------------------------------------------------------------------------------
--- Aspose.Email for .NET [21.4.0.0] SMTP Client diagnostic log
--- 
--- Started: 01/12/2022 13:43:03
-------------------------------------------------------------------------------

Smtp client[1|01/12/2022 13:43:03]: 
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Connect to: xxx.xxx.com:25 SecurityOptions.SSLExplicit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Environment version: 5.0.15 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> OS version: Unix 4.15.0.188 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Assembly title: Aspose.Email for .NET <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Assembly version: 21.4.0.0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: 
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp server[1|01/12/2022 13:43:03]: 220 xxx.xxx.com ESMTP Postfix
Smtp server[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: EHLO xxx.xxx.com
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp server[1|01/12/2022 13:43:03]: 250-xxx.xxx.com
Smtp server[1|01/12/2022 13:43:03]: 250-PIPELINING
Smtp server[1|01/12/2022 13:43:03]: 250-SIZE 10240000
Smtp server[1|01/12/2022 13:43:03]: 250-VRFY
Smtp server[1|01/12/2022 13:43:03]: 250-ETRN
Smtp server[1|01/12/2022 13:43:03]: 250-STARTTLS
Smtp server[1|01/12/2022 13:43:03]: 250-ENHANCEDSTATUSCODES
Smtp server[1|01/12/2022 13:43:03]: 250-8BITMIME
Smtp server[1|01/12/2022 13:43:03]: 250-DSN
Smtp server[1|01/12/2022 13:43:03]: 250 SMTPUTF8
Smtp server[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: STARTTLS
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp server[1|01/12/2022 13:43:03]: 220 2.0.0 Ready to start TLS
Smtp server[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp client[1|01/12/2022 13:43:03]: EHLO xxx.xxx.com
Smtp client[1|01/12/2022 13:43:03]: 
01/12/2022 13:43:03	
                   	
Smtp server[1|01/12/2022 13:43:19]: 250-xxx.xxx.com
Smtp server[1|01/12/2022 13:43:19]: 250-PIPELINING
Smtp server[1|01/12/2022 13:43:19]: 250-SIZE 10240000
Smtp server[1|01/12/2022 13:43:19]: 250-VRFY
Smtp server[1|01/12/2022 13:43:19]: 250-ETRN
Smtp server[1|01/12/2022 13:43:19]: 250-ENHANCEDSTATUSCODES
Smtp server[1|01/12/2022 13:43:19]: 250-8BITMIME
Smtp server[1|01/12/2022 13:43:19]: 250-DSN
Smtp server[1|01/12/2022 13:43:19]: 250 SMTPUTF8
Smtp server[1|01/12/2022 13:43:19]: 

As you can see in the log, the response after the STARTTLS command is 16 seconds later. When I connect and send with openssl, the response is instant. Both in side the docker container, as on the docker host.

openssl s_client -connect xxx.xxx.com:25 -starttls smtp < testmail

We are using the ServicePointManager.ServerCertificateValidationCallback to check the certificate of the smpt server, but during debug that code is not causing delays.

I hope anyone here has an idea how to improve this.

Kr,
Jeroen

Hello, @Jeroen_HRorganizer.com

The problem seems related with the Postfix server you are using. Try different TLS server settings, try to enable activity logging on the server.

Thanks.

Thank you very much, @DmitryS. Unfortunately the server is not under control of my company, it is a client smtp server. As openssl can do it fast, I figured it should also be possible with Aspose… Kr, Jeroen

@Jeroen_HRorganizer.com

BTW, I tried searching for the cause of your problem, and found something similar:

Try setting the certificate with the ClientCertificates property.

Thanks.

1 Like

Really appreciate the help @DmitryS!

I tried this today but there was no significant improvement.

Could this delay of the smpt server an anti spam measure?
https://tldp.org/HOWTO/Spam-Filtering-for-MX/smtpdelays.html

Have a great weekend!
J

Hello @Jeroen_HRorganizer.com

Thanks :slight_smile:

Could this delay of the smpt server an anti spam measure?

It’s possible.
I suppose enabling server-side activity logging would probably help to investigate the delay issue.

1 Like

Hi @DmitryS, Comparing the server logs to the client logs reveiled that the delay was caused during the sending/receiving of the EHLO command itself. So we now assume it is a networking problem. Thanks, again!

Hi @Jeroen_HRorganizer.com,

Glad you’re on the way to solving the issue. Feel free to contact us if you have any other questions.

Thanks for sharing and have a nice day.