Troubleshooting Postfix Email Sending Issues on EC2 Instance

amazon ec2postfix

My client spun up a new ec2 instance and gave me ssh access. I have set up a LAMP system serving a WordPress site. Everything is working nicely, except email isn't being sent.

I have not done anything, as far as, email configuration, yet.

When I try from the command line, the following:

sendmail MY-EMAIL@gmail.com < ~/email.txt

No feedback is returned. When I check the end of /etc/maillog file, there is the following:

TIME IP postfix/pickup[#]: #: uid=1000 from=<ec2-user>
TIME IP postfix/cleanup[#]: 7644720EDF: message-id=<20200524122559.7644720EDF@IP.ec2.internal>
TIME IP postfix/qmgr[#]: 7644720EDF: from=<ec2-user@IP.ec2.internal>, size=355, nrcpt=1 (queue active)
TIME IP postfix/smtp[#]: connect to gmail-smtp-in.l.google.com[142.250.31.26]:25: Connection timed out
TIME IP postfix/smtp[#]: connect to gmail-smtp-in.l.google.com[2607:f8b0:4004:c09::1a]:25: Network is unreachable
TIME IP postfix/smtp[#]: connect to alt1.gmail-smtp-in.l.google.com[172.253.116.26]:25: Connection timed out
TIME IP postfix/smtp[#]: connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:400b:c02::1a]:25: Network is unreachable
TIME IP postfix/smtp[#]: connect to alt2.gmail-smtp-in.l.google.com[2a00:1450:400c:c03::1b]:25: Network is unreachable
TIME IP postfix/smtp[#]: 7644720EDF: to=<MY-EMAIL@gmail.com>, relay=none, delay=60, delays=0.01/0.01/60/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[2a00:1450:400c:c03::1b]:25: Network is unreachable)

I've tried sending to other domains, such as yahoo.com and live.com with similar results.

Some of the suggestions solutions, I have across, suggest setting (from server fault):

inet_protocols = ipv4

But that seems like going backwards a bit.

There also been some mentioning of setting up Amazon SES or filling out an Amazon request for port 25 access. Anything going through AWS, I would need to my client to do.

I just want a low key, low maintenance solution. The site, likely won't sending more than a couple of dozen emails or so, a week.

Any suggestions on how to get through this?

Best Answer

Cloud providers have a problem when you can simply send email out via port 25, as people register and start sending email out as ceo@amazon.com or such like, which leads to the providers IP ranges being blacklisted.

To get around this, they have services like SES where you have to prove you own the email/domain before you can send email.

If you want to brave the wild west, you can request AWS to remove the port 25 limits. But there is still a good chance that you will find your email ending up in junk/spam folders.

Therefore easiest answer would be to either contact the client to set up SES on AWS, or use another SMTP service, configured in either postfix, or directly in your application.

If the client already has email set up for the domain already, you can likely use an account on that service, for low traffic.