Skip to content

Unable to Send Email via Exchange Online SMTP – Connection Fails on Port 25 and 587

0

We are encountering a critical issue with our EC2-based production application which sends email via Exchange Online SMTP servers. The connection to the mail server is now failing, even though the same setup has been working for months.

We are unable to connect to ryansg-com.mail.protection.outlook.com on port 25 and 587.

Error observed: Couldn't connect to host, port: ryansg-com.mail.protection.outlook.com, 25; timeout 10000; Telnet also fails for this domain on port 25 and 587, but telnet to smtp.gmail.com on port 25 succeeds, confirming partial outbound SMTP access.

Current Setup: Elastic IP is atatched to EC2 Public DNS: .compute-1.amazonaws.com Outbound IP check (curl ifconfig.me): returns correct EIP Security Groups: All attached security groups allow egress to 0.0.0.0/0 (no port restriction) Network ACLs: Allow all traffic both inbound and outbound DNS resolution for mail server works via nslookup

Troubleshooting Done: Validated DNS is resolving correctly to Exchange Online IPs.

Verified the correct EIP is being used via curl https://ifconfig.me.

Ensured route table points to the current NAT Gateway for all required CIDRs and 0.0.0.0/0.

Confirmed security groups and NACLs allow outbound on all ports.

Manually telnet to other SMTP servers like Gmail on port 25 works — indicating port 25 is not globally blocked.

Verified the NAT Gateway is active and has an EIP attached.

Subnet routing is consistent; no route propagations are missing.

2 Answers
0

This issue is likely related to AWS's default restriction on outbound SMTP traffic. Here's what's happening and how to resolve it:

By default, AWS blocks outbound traffic on port 25 (SMTP) for all EC2 instances and Lambda functions to prevent potential spam. This is a standard restriction across AWS environments, even if your security groups and NACLs allow the traffic.

While you mentioned that telnet to Gmail on port 25 works, this could be inconsistent behavior or potentially related to specific IP ranges. The core issue remains that AWS generally restricts port 25 traffic.

Here are your options to resolve this:

  1. Request removal of the port 25 restriction:
  • Submit a request to AWS Support using the "Request to remove email sending limitations" form
  • Provide details about your legitimate use case
  • Include your instance ID in the request
  • Note that approval can take up to 48 hours
  1. Use alternative ports that aren't restricted:
  • Try port 587 (TLS) or port 465 (SSL) if your Exchange Online configuration supports them
  • These ports are generally more secure and don't require special permission
  1. Use Amazon Simple Email Service (SES):
  • Consider switching to AWS SES, which is designed specifically for sending emails from AWS resources
  • It's a managed service that handles deliverability and reputation management

Since you mentioned that port 587 is also failing, you should verify that your Exchange Online configuration properly supports this port, as it should not be restricted by AWS by default. Double-check your Exchange Online settings to ensure they're correctly configured for the alternative ports.
Sources
SMTP issue, not able to send out Email through the port | AWS re:Post
Not able to send mail from EC2 | AWS re:Post
Amazon SES SMTP issues - Amazon Simple Email Service
Amazon SES SMTP issues - Amazon Simple Email Service

answered a year ago

0

For everything you described, the issue is most likely related to IP reputation management by Microsoft Exchange Online. Here's how you could resolve this:

Immediate Verification Steps:

  • Check if your IP is blacklisted using Microsoft's Remote Connectivity Analyzer
  • Review your EIP's reputation at: https://sender.office.com
  • Check major RBL (Realtime Blackhole Lists) for your EIP

Temporary workaround:

Allocate a new EIP and switch to it Configure proper PTR records for the new EIP Implement proper email authentication (SPF, DKIM, DMARC)

Hope it helps.

BR Alberto

AWS
EXPERT

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.