I'm trying to configure DNS for handling mail across multiple subdomains, where each subdomain has its own mail server. My goal is to route mail for user@%subdomain%.example.com to the server hosted under %subdomain%.example.com.
Example of desired configuration:
- Mail for [email protected] should be handled by abcde.example.com server
- Mail for [email protected] should be handled by xyz.example.com server
And so on for all possible subdomains. There are many subdomains, so manually adding an MX record for each one is not an option.
What might work
_smtp._tcp.*.example.com. IN SRV 0 0 25 %.example.com.
This configuration looks logical, but I'm not sure how well it's supported by mail servers. I don't know if something similar is possible for IMAP and POP3.
My questions
- What DNS records need to be created to implement such a routing?
- Is it possible to set up a wildcard MX record that will automatically route mail to the corresponding subdomain?
- If a wildcard MX record is not possible, how can the process of creating MX records for new subdomains be automated (preferably in a way that doesn't take much time, perhaps using dynamic DNS)?
What doesn't work
- Wildcard routing of all subdomains to a single domain, like
IN MX 10 central-mail.example.com.
. Such a configuration is only acceptable if the email can then be routed to the correct server without needing to decrypt the packet content (like SNI in TLS/SSL).
I would appreciate a detailed explanation of the necessary DNS records and any additional recommendations.