5

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?

Braiam
  • 622
  • 4
  • 23
pato.llaguno
  • 161
  • 4

2 Answers2

22

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.

Stuggi
  • 3,366
  • 4
  • 17
  • 34
  • so, i did manage to make the config, if i use a dns checker to check on the MX subdomian i get the correct amazon smtp server, but if i send a mail from gmal to that subdomain i get DNS Error: 69557 DNS type 'mx' lookup of app.binestarpatrimonial.com responded with code NXDOMAIN Domain name not found: app.binestarpatrimonial.com – pato.llaguno Oct 14 '20 at 17:31
  • It's probably due to DNS propagation, it can take a couple of days for DNS changes to propagate. I can't find binestarpatrimonial.com at least, is this the real domain or a fictions one? – Stuggi Oct 14 '20 at 17:34
  • that was a typo, its bienestarpatrimonial.com, and the subdomain is app.bienestarpatrimonial.com, still get the same error with no typo, mxtool checker gives me the actual dns, so apparently its propagated – pato.llaguno Oct 14 '20 at 17:37
  • It seems to be propagated alright: https://dnschecker.org/#MX/app.bienestarpatrimonial.com – Stuggi Oct 14 '20 at 17:40
  • thats what's weird, sending a mail to it gives as if it isnt – pato.llaguno Oct 14 '20 at 17:41
  • Might be that Google has cached an NXDOMAIN somewhere or something, I'd give it a couple hours and try again. – Stuggi Oct 14 '20 at 17:41
  • Thx, it worked now – pato.llaguno Oct 14 '20 at 17:53
  • 1
    An alternative to forwarding messages from your mailserver : rather than receiving your messages directly you let the app poll a mailbox that resides on your actual mailserver (or get a helper application to that for you; fetchmail is common linux tool for that) That has some side benefits as well since you automatically will get the anti spam and anti virus security you already have on your existing mail server – Bob Oct 15 '20 at 07:30
10

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 foo@bar.example.com if the regular addresses are @example.com) or set up some forwarding solution with the other mail service (eg forward foo@example.com to wherever you can deliver mail for the application).

Håkan Lindqvist
  • 33,741
  • 5
  • 65
  • 90