I have an app hosted in AWS, my mail service is not on AWS, I'm using a hosting in hostgator due to pricing since I need 500+ simple mail accounts.

My DNS points to my email service and it works correctly.

The part I'm lost in is that I'm trying to receive emails in a specific address so that my app can process it. Is there a way so that some addresses are sent to a secondary MX record, or if the address is not found in the first will it go look at the second? Or the second priority MX record is only if the first in offline?


Solution 1:

MX records are used according to priority value in the records.

The record with the lowest priority is used first, then the higher ones until one responds. If there are multiple records with the same priority, one is randomly selected (this is how you generally do load balancing if you have multiple mail servers accepting incoming connections).

The MX records only dictates which mail servers are responsible for a specific domain, it doesn't deal with individual recipients. So a sending server will only use secondary records if the primary server doesn't respond to its connection attempts, not if the primary server rejects the message.

What you're trying to achieve is only doable at the DNS level if you use a subdomain for messages destined for your application. That way you can have the MX records for example.com point to your mail servers and the MX records for app.example.com to point towards your application.

If you need to use the same domain for both, you'll need to configure your mail server to forward e-mail messages to your application. This can usually be done a couple of different ways depending on the mail server/hosting provider.

Solution 2:

MX records cannot solve this, multiple records (with possibly different priorities) can be used for redundancy, but the service is expected to be the same (accept the same addresses).

What you can do is either have the address that your application processes at a different domain (eg [email protected] if the regular addresses are @example.com) or set up some forwarding solution with the other mail service (eg forward [email protected] to wherever you can deliver mail for the application).