Sending temperror (4xx) response codes from SES incoming lambda

25 Views Asked by At

I want to use AWS SES’s SMTP server as my sole SMTP server for my domain, using my own LDA (Dovecot) for email storage. To do this, I want to have SES accept incoming mail for my domains, save it in S3, and invoke a Lambda function, which delivers the message. I’ve written code to do this, relaying the message from the Lambda to a small web API that can do a spam check and deliver the message.

The problem comes in when the message is invalid in some way: whether spam, or incorrectly addressed, etc.

I’d like my Lambda to ideally return a 4xx or 5xx response to the sender during the SMTP session, but I cannot determine whether or not this is possible. The documentation doesn’t say so, but does SES always send back a 250 to the sender of the messages it receives, and then invoke the Rule Set? If that’s the case, I need to develop my own handlers for bounce messages, temporary failures, etc.

I was hoping the RequestResponse option made this synchronous so the RuleSet could communicate back to the sending SMTP server. Is that not the case? If not, where do I find examples of how to send a bounce message, beyond the RFCs?

1

There are 1 best solutions below

0
koehn On

After reading RFCs and coding up a prototype, it appears that SES will always accept messages with a 250, and will not subsequently deliver an NDR (it rejects the empty <> MAIL FROM). At that point you need another mail server to handle delivery, and then there’s not much point to using SES as your primary inbound mail server.

Still, you can use SES for outbound mail, either by having users connect to it directly with credentials, or by having your existing mail server relay off it. This gives you the benefit of very high reputation IPs and not having your users’ outbound email rejected.