Quite frequently, AWS users experience EC2 SMTP Connection timed out error when sending emails.
This is usually caused due to mail server security restrictions, network routing issues or even port blocks at ISP or AWS levels.
Here at Bobcares, we provide Server Administration and Maintenance services to AWS account owners.
We’ll take a look at how we resolve SMTP errors in EC2 instances.
What is AWS EC2 “Connection timed out” error in SMTP?
When you or your customers try to send mails using your mail server in the AWS EC2 instance, it performs a series of steps. It will establish the connection to the mail server and then deliver the mails.
This includes authenticating an email account, verifying the email server settings, etc. It also invokes the mail transfer and delivery agents, connects to the remote mail server, and so on.
If any of those steps fail for a hundred different reasons, the mail delivery process fails.
Today, we’ll look at the top few reasons for this failure, and the fixes for it:
Resolving AWS EC2 “Connection timed out” error in SMTP
This happens because the email account user is unable to connect to the mail server.
For example, in a customer’s AWS server, when a user tried to send mails to a Gmail address, he got the error:
Jan 10 12:52:45 postfix-xxxxx postfix/smtp[4001]: xxxx: to=, relay=none, delay=2323, delays=2233/0.01/90/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[64.233.177.27]:25: Connection timed out)”
To resolve this error, first, we need to determine the cause of the error.
Local connectivity issues, AWS throttling for port 25 on EC2 instances, server firewalls or mail server misconfiguration, anything can lead to such errors.
If you are facing this error, and need help, click here to request expert assistance.
How to fix AWS EC2 SMTPConnection timed out error
This error occurs mainly due to 3 main reasons:
- Email client unable to connect to the mail server
- AWS limiting the connections to port 25 of the SMTP server
- Email server unable to connect to a remote mail server
Three variations of this error are:
-
status=deferred (connect to domain.com[***.*.***.12]:25: Connection timed out)
-
postfix/smtp[1261]: connect to domain.com[***.*.***.12]:25: Connection timed out
-
qmail: 1291975084.251298 delivery 1234: deferral: Sorry,_I_wasn’t_able_to_establish_an_SMTP_connection._(#4.4.1)
All these happen because of some connectivity issues between the email sender and the recipient mail server. Possibly due to a server misconfiguration, port blocks or connectivity issues.
To fix this, you’ll need to verify the connectivity from the sender’s PC to the mail server. Then, check the firewall rules in the server and confirm that there are no connectivity issues or throttling set within the EC2 instance.
Things can go wrong when editing firewall rules or mail server configuration files. So the edits have to be done carefully.
However, if you need help, our server experts can fix this for you in an hour. Click here to go to our server administration services page.
Fixing the “Connection timed out” error in SMTP
For users to send mails via AWS EC2 instances, the mail server connectivity and the SMTP ports should be working fine. This includes allowing SMTP port in the firewalls, ensuring proper network connectivity in EC2, resolving DNS issues, etc.
Even a slight misconfiguration in the mail server or email client settings can cause email delivery to fail.
Verifying connection
As the first step in debugging an email connectivity error, we make sure the mail server is working fine and allows SMTP ports.
If there are errors while connecting to the remote mail server, we first confirm that network connectivity. Also, we make sure that the security group outbound (egress) rules allow traffic to the SMTP server on TCP port 25, 587, or 465.
Further, we use the telnet command to check the connection from the command-line. Based on the port in use, we use one of the commands,
telnet email-server.com 587
telnet email-server.com 25
telnet email-server.com 465
Remove AWS EC2 throttling limits
In case the issue persists, we look up the mail server IP address and AWS EC2 throttling limits.
Amazon EC2 restricts traffic on port 25 of all EC2 instances by default. Therefore, we request AWS to remove the port 25 restrictions on the instance.
For this, we log in to the AWS account and open a Request to Remove Email Sending Limitations form. Here, we provide the details of our use case.
Also as per customer requirements, we often provide the AWS-owned Elastic IP addresses that the server uses to send outbound emails. This helps to reduce the occurrences of emails sent from the Elastic IP addresses being marked as spam.
Email errors can also occur due to mail server configuration issues or email routing problems.
If you need help, our server experts are on standby 24/7. Click here to open a server administration request.
Conclusion
In short, EC2 SMTP Connection timed out error shows up due to network connection errors or Amazon’s port limits. Today we’ve seen the common causes for this error, and how to fix them.
0 Comments