Kamil N.
Kamil N.

Reputation: 91

AWS simple email service works on localhost but not on production Amazon EC2 server

So I am working on a mailing API for my website. The scenario is as follows:

  1. Customer connects to endpoint.
  2. API endpoint handles request and sends email using mailing service (which is based on aws sdk).
  3. API returns Ok/BadRequest based on result.

When I am doing this with my API running on localhost everything works fine and I am receiving email on my mailbox as expected. But when I run my API service on Amazon EC2 instance I am getting this:

Response status code does not indicate success: 404 (Not Found)

I double checked that I have .aws/credentials file both on my localhost machine and EC2 instance (ubuntu 16.10). I can reach my API service running on EC2 instance just fine, because I get the BadRequest response. The problem is when mailing service tries to send an email using amazon SES. I believe it's not the code itself because it runs fine on localhost. Any ideas?

Upvotes: 4

Views: 1850

Answers (1)

Edmund P Charumbira
Edmund P Charumbira

Reputation: 528

In case someone else has the same problem, changing to port 587 solved the problem.

Ec2 has a very strict throttle on port 25 by default. You can get whitelisted on an IP-by-IP basis by filling out a formal request, but if you're sending to SES, our recommendation is to use port 587 or 2587.

For more on the EC2 throttle on port 25: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-port-25-throttle/

And for more about SES's available SMTP ports: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html

Upvotes: 5

Related Questions