Score:0

Unable to send mail via SES from EC2 instance

tr flag

I have an EC2 instance running Magento. I'm trying to get AWS SES set up so that we can send transactional emails to customers and to our staff internally, however, I keep getting timeout errors.

The domain is set up and verified in SES, I have an SMTP user configured. The server is running Debian 10 and Sendmail as its MTA. Sendmail is configured to use SES' SMTP user credentials for sending mail.

Trying to send a test email via command line gives this result:

/usr/sbin/sendmail -vf [email protected] [email protected]

From: [email protected]
To: [email protected]
Subject: AWS SES test email

This is a test message sent from SES using Sendmail

Results:

[email protected]... Connecting to [127.0.0.1] via relay... 220
mta.example-domain.com ESMTP Sendmail 8.15.2/8.15.2/Debian-14~deb10u1;
Tue, 19 Oct 2021 00:23:05 -0400; (No UCE/UBE) logging access from:
localhost(OK)-localhost [127.0.0.1]
EHLO mta.example-domain.com 250-mta.example-domain.com Hello localhost [127.0.0.1], pleased to meet you 250-ENHANCEDSTATUSCODES
250-PIPELINING 250-EXPN 250-VERB 250-8BITMIME 250-SIZE 250-DSN
250-ETRN 250-AUTH DIGEST-MD5 CRAM-MD5 250-DELIVERBY 250 HELP
VERB 250 2.0.0 Verbose mode
MAIL From:<[email protected]> SIZE=136 [email protected] 250 2.1.0 <[email protected]>...
Sender ok
RCPT To:<[email protected]>
DATA 250 2.1.5 <[email protected]>... Recipient ok 354 Enter mail, end with "." on a line by itself
. 
050 <[email protected]>... Connecting to aspmx.l.google.com. via esmtp... 050 <[email protected]>... Connecting to
alt1.aspmx.l.google.com. via esmtp... 050 <[email protected]>...
Connecting to alt2.aspmx.l.google.com. via esmtp... 050
<[email protected]>... Connecting to alt3.aspmx.l.google.com. via
esmtp... 050 <[email protected]>... Connecting to
alt4.aspmx.l.google.com. via esmtp... 050 <[email protected]>...
Deferred: Connection timed out with alt4.aspmx.l.google.com. 250 2.0.0
19J4N5Q0004977 Message accepted for delivery [email protected]...
Sent (19J4N5Q0004977 Message accepted for delivery) Closing connection
to [127.0.0.1]
QUIT 221 2.0.0 mta.example-domain.com closing connection

If I try to telnet from the server to the SES endpoint, I get this:

telnet email-smtp.us-east-1.amazonaws.com 587

Trying 34.194.114.91...
Connected to email-smtp.us-east-1.amazonaws.com.
Escape character is '^]'.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-31RAO5EPD a2sb2LhwUqPVXiyXQJod
451 4.4.2 Timeout waiting for data from client.
Connection closed by foreign host.

In my EC2 instance currently, I have all ports open for inbound and outbound traffic (not ideal, I know, but this is temporary until I can figure this thing out). I'm completely at a loss for what's happening here. Any help is greatly appreciated!

Tim avatar
gp flag
Tim
Just to confirm, sendmail is passing email to SES to send out? In your "results" (not sure where that comes from) I would have thought we'd see SES headers. I'd be surprised if you can telnet to SMTP 587 as it's TLS.
Chris Hood avatar
tr flag
Yes, sendmail is set up to connect to SES using SMTP credentials of the SMTP user I set up in SES. Trying to telnet to 465, 587, and 25 all give similar results: telnet email-smtp.us-east-1.amazonaws.com 587 (or 476, or 25) Trying 18.211.27.116... Connected to email-smtp.us-east-1.amazonaws.com. Escape character is '^]'. 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-3D12GBQSD c05pLyZapnEAuiPGvLo3 451 4.4.2 Timeout waiting for data from client. Connection closed by foreign host.
Chris Hood avatar
tr flag
@Tim if there's a better way to get the EC2 instance to send out emails using SES I'm open to it. I followed this guide trying to set it up: https://gist.github.com/amanjuman/1121efff59a69d6d3d76de2b35ba9afa
Tim avatar
gp flag
Tim
That's one of the AWS services I haven't used. If you can clarify your question a bit that would be good. Where did "results" come from - are they mail headers? From the email sent by EC2 to SES? Or email headers for a reply? Does SES kept metrics or logs? Need a bit more info to help.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.