Hacker News new | past | comments | ask | show | jobs | submit login
Trap and test AWS SES emails locally (github.com/kamranahmedse)
63 points by anonfunction on Nov 20, 2023 | hide | past | favorite | 28 comments



Does anyone have a good reason they normally fall back on for using the AWS SDK vs the provided SMTP bridge? Rate limits or anything of the sort?

I find that basically every transnational email service supports SMTP so I normally code to that and call it a day…


We switched from using SMTP to the AWS SDK for SES because when sending an e-mail the SDK returns the unique message ID of the e-mail. This allowed us to have a special process for handling bounces in our software by using an SNS HTTP endpoint. So the SDK makes sense for use cases where the SMTP protocol doesn't provide enough information.


Hm, many MTAs do return a unique queue ID when they accept a message over SMTP. Does SES not implement that?


Any examples? Curious how they do it. Just extra info in the 250 OK response to the DATA command?


RFC 822 defines a Messsge-id header that the client can set, and most MTAs can be configured to add one if not set by the client. IIRC, they're supposed to be globally unique, but like so many things in email, ymmv.

Edit: oh, yeah, there's also a queue id returned in the 250 response (in postfix, at least)


Yeah, just in the text of the OK response. So I guess it isn't really very structured. Seems like it would be a useful ESMTP capability to add though - queue identifier and MTA-assigned message-ID.


Why would the Message-ID (that you assign) not work for this purpose? Perhaps the SNS notification doesn't include the message-id?


SES does not allow the caller to set the id of the message and instead assigns one when you make the call.

It is a bit painful for idempotency.


Interesting thanks. I can imagine that an email sending service wants to be in control of message-id's (would still be interesting to hear the actual rationale).

Perhaps SMTP could use an extension with a new (pipelined) command after DATA, so a client can retrieve the assigned message-id.

I wonder how common it is for message-id's to be overwritten. I must have run into this SES behaviour (along with other problems) when trying to use it as backup for outgoing mail for my mail server: My DKIM signatures include the message-id header, overwriting the header will invalidate them.


Thanks for noting this, this is a pretty solid reason — I thought most people tried to correlate other fields on the incoming email but this also makes sense


If you want to test SMTP mail delivery, there's MailCatcher: https://mailcatcher.me/


There are several alternatives. Most of them, including mailcatcher, seem to be unmaintained.

Mailpit is an alternative that has regular updates: https://mailpit.axllent.org/


> Most of them, including mailcatcher, seem to be unmaintained.

MailCatcher is great. It "just works" and has Docker images for both AMD64 and ARM64 CPUs.


Thanks for the link - we’ve been using mailhog for local smtp testing and it still works ok for basic tasks, but it’s not maintained any more.


Pitching my own: https://github.com/mjl-/mox has a "mox localserve" subcommand that runs a mail server on localhost for testing, including a pedantic mode and special addresses that cause failure conditions you may want to test for. This is actually a full mail server (SMTP, IMAP and much more) and it comes with a webmail client. The "localserve" mode was just so easy to implement that I couldn't resist.


Yeah thanks for this, I’ve been using it for years! Recently switched to mailslurper:

https://github.com/mailslurper/mailslurper


Can’t use an IAM role to auth to the bridge, it only works with user’s keys.


That's a really great point. I was wondering the same thing as the comment root but this is enough for it to make sense. At the end of the day, having a wrapper email/notification class with an SMTP and moving to a specific SES implementation seems like it'll always be a safe dev path.


Not for production stuff, but for quick hacks I'll wire it up to SNS and send emails via SNS queue.


In theory you get higher effective sending rates, however I've not actually proven how much faster in practice.


You should get this merged into awslocal

Edit: uh never mind https://docs.localstack.cloud/user-guide/aws/ses/


Someone needs to invent a protocol for transferring mail and make it simple.


Simple Email Service


Why would I use this instead of the AWS SES Simulator ? [1]

[1] https://docs.aws.amazon.com/ses/latest/dg/send-an-email-from...


> For billing purposes, emails that you send to the Amazon SES mailbox simulator are the same as any other email you send using Amazon SES. In other words, we bill you the same amount for messages that you send to the mailbox simulator as for those that you send to regular recipients.


Fair enough, I didn't know SES simulator was only zero-affecting for stats and quotas.

However then surely this thing is just re-inventing the wheel that LocalStack already invented ?


Somewhat offtopic, but is there a simple email service in the sense of SMTP + IMAP/POP + simple email web interface to use AWS as a end-user email service?


I suspect you meant something more independent, but technically yes, AWS provides this: https://aws.amazon.com/workmail/

While SES can handle both inbound and outbound mail, I think Workmail is the only way to get IMAP and actual hosting of email. I imagine you could set up https://mailinabox.email/ on the cheapest EC2 instance and use SES for outbound, though.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: