'AWS SES - Store email sent to`[email protected]` in S3, receive other emails to `[email protected]` in iCloud?
Short Description
I am trying to figure out how to use AWS SES to receive email and store this in an S3 bucket, but only for a specific email address of a domain. The rest of the emails I would like to be handled by my email provider iCloud (or any other provider).
Why
I am working on a CDK Construct, and in order to test this construct I need to receive an email to a specific email address ([email protected] for example). I also need to read the contents of this email in order to complete the testing, however the domain I own is already setup to receive emails to other email addresses within that domain ([email protected], and [email protected] for example). Currently, this domain is registered through NameCheap (arbitrary DNS registrar) and the email client is setup through iCloud.
The Problem
The issue I am finding is that in order to receive email from AWS SES, I need to configure MX records for my domain on NameCheap to point to AWS SES. If I do this then I will no longer be able to receive emails from any other email addresses on my domain such as [email protected] or [email protected] on iCloud (or any other email provider) as emails can only go to one server based upon the highest priority MX record.
In essence a pseudocode example of the logic I would like to have:
if email_address == '[email protected]' then
save_to_s3_bucket()
else
default_send_to_icloud()
Investigated Solutions
Purchase second domain
One thing I could do, is apply a rule in iCloud that would forward all emails from the
[email protected]email to go to any other address. The only way this would work is if I purchased a second domain and forwarded emails to an address on this domain. Here I could setup the MX records with no conflict as this domain would be used only for this purpose, and save to S3 bucket.I don't like this approach because now I have to purchase a recurring fee of $12/year for a singular purpose of receiving an email for a test. This seems like an overkill solution for my problem.
Send email to S3 Bucket Endpoint
This is an imaginary solution (to the best of my knowledge), but wanted to show I have investigated this route. The idea would be if AWS S3 offered a service where they controlled a domain that anyone could send an email to, and then you could configure your S3 bucket to accept emails from some REGEX domain string and allow these to be saved to your bucket as a file. (I haven't fleshed out what the whole process is, but just giving rough concept)
This does not work as this is not a current offering from S3 (but would be pretty cool if they added it).
Forward to iCloud The last option feels like a configuration nightmare, but the idea would be to configure AWS SES to receive all emails by setting the MX records of the domain to point there. Then we could apply rule-based filter to forward the emails that we aren't saving to S3 on to the iCloud server.
This approach has quite a few question marks, such as would the email appear to be sent from SES? How would I respond via iCloud to emails? Would need to investigate latency, dropped emails, etc. from SES.
I really don't want to do this as it feels like a nightmare of configuration. I have not done this though so please let me know if it is simpler than I might imagine.
These are the only solutions I have found thus far, are there any other solutions? I find it hard to believe I am the only person who has come across an issue like this, but googling for a solution like this is extremely difficult.
Solution 1:[1]
After some searching I found a solution by using a subdomain of my original domain. If I do this, then I can maintain the original MX records of my root domain and receive emails to my iCloud (or any other provider). Next I can add MX records to a subdomain, all emails will now be directed to AWS SES.
| Type | Host | Value | Priority | TTL |
|---|---|---|---|---|
| MX | my-domain.com | mx04.mail.icloud.com | 10 | Automatic |
| MX | my-domain.com | mx07.mail.icloud.com | 10 | Automatic |
| MX | testing.my-domain.com | inbound-smtp.us-east-1.amazonaws.com | 10 | Automatic |
The benefit of doing it this way is that subdomains are free in most (all?) DNS registrars.
Now all emails from [email protected], [email protected], etc will go to iCloud. All emails to [email protected], [email protected], etc will go to AWS.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Spencer Duball |
