SmtpException: Syntax error in parameters or arguments. The server response: 5.5.4 Invalid domain name

Our project uses Aspose.Email for .Net (version 21.8.1) to connect to SMTP server and send emails. When our project was hosted on Kestrel in Windows we got no errors and can connect to the SMTP server and send emails. but when we host our project to k8s, we get the below error:

at Aspose.Email.Clients.EmailClient.CreateConnection()
at . (Boolean , )
at . (Int32 , )
at . ( )
at . ()
at . (IAsyncResult )

at . (String , Int32 , SecurityOptions , SecurityOptions )
at .(String , Int32 , SecurityOptions )
at . ( )
at . (Object )
at . ()
at . (IAsyncResult )
—> SmtpException: Syntax error in parameters or arguments. The server response: 5.5.4 Invalid domain name

Hello @sandy4aspose,

Thank you for using our product.

Could you try enabling activity logging for SMTPClient and send us the .log file. The tutorial on how to enable it is here.

hi margarita.samodurova,

attached is the log file we have collected, looking forward to your reply.
smtp_2023-9-28.zip (872 Bytes)

Hi @sandy4aspose,

The error message you’re encountering, “501 5.5.4 Invalid domain name,” typically indicates an issue with the EHLO (Extended Hello) command sent by SMTP client. The EHLO command is used to identify the client to the SMTP server and negotiate features and options for the SMTP session.

It seems that the SMTP server is rejecting the EHLO command because it considers the hostname not being recognized or accepted by the SMTP server for some reason.

Here are some ideas to potentially resolve this issue:

  • Verify that the hostname used in the EHLO command is correct. In your log, it appears as “dbp-appsvc-6dc8f555db-dxcv2.(none).” Ensure that this hostname is valid and recognized by the SMTP server.

  • Ensure that the hostname you use in the EHLO command is a fully qualified domain name (FQDN) and not just a hostname without a domain.

  • In Kubernetes, make sure that the hostname used in the EHLO command is correctly derived from the Kubernetes pod’s hostname.

  • Verify that DNS resolution is working correctly within your Kubernetes cluster. The SMTP server should be able to resolve the hostname you provide in the EHLO command to an IP address.

  • Check if the SMTP server is performing a reverse DNS (rDNS) lookup on the IP address from which the EHLO command is coming. Ensure that the rDNS entry for your pod’s IP address resolves to a valid hostname.

  • Ensure that Kubernetes cluster’s network configuration allows outbound traffic on SMTP port to reach the SMTP server.

  • If possible, check the log of SMTP server for more information. It might provide additional details on what it considers to be an invalid domain name.

  • Within Kubernetes pods, you may check the /etc/hosts file and the DNS configuration to ensure that the hostname is correctly mapped to the pod’s IP address.

Please share your feedback.
Thanks.