Sendmail: forward wildcard MX to a single email address

mx-recordsendmailwildcard

I'm trying to set up sendmail to forward all email to **@ **.crm.mycompany.com to crm@mycompany.com. Unfortunately my sendmail-fu isn't up to it and I can't find anything useful on Google.

My plan was to use an existing internal Linux server (CentOS 5), port-forward SMTP traffic from one of our spare external IPs to it and set up a wildcard MX record to point to that external IP. However I haven't managed to make sendmail work with this.

I have managed to get the non-wildcard case working, e.g. by adding test.crm.mycompany.com to /etc/mail/local-host-names and adding a "@test.crm.mycompany.com" line to virtusertable. However I can't see how to do the wildcard case. These files don't seem to accept wildcards in the domain names and as far as I can see the only configuration that can manage wildcard DNS is the relay_entire_domain. However if I configure my test domain for relay then it ignores the virtusertable and procmail and just tries to relay the email on – so unless I can trigger either of those for relay emails I don't think I can manage this anyway. And a final wrinkle here is that I can't seem to set $=m to mycompany.com – it's always our internal domain name (the hostname is server.internal.lan and $=m is internal.lan) and DOMAIN(mycompany.com)dnl in sendmail.mc tries to include a file from /usr/share (?).

Is what I'm trying to do possible? I was hoping to reuse an internal server for this – do I need to put a server outside the firewall or in the DMZ instead? Would this be easier with postfix or something else instead?

Thanks for any suggestions!
Rupert.

Best Answer

As you noted, you need a DNS wildcard.

When mail from the wildcard addresses comes in, sendmail doesn't know what to do with it. You can fix that by adding a sendmail rewrite rule to rewrite the wild subdomain parts into the main domain part.

in your sendmail.mc:

LOCAL_NET_CONFIG  
R $+ < @ $+ .example.com. > $*    $: $1 < @ example.com > $3       dnl

Note that you need a tab to separate the left-hand side rule from the right-hand side replacement. ($* ends the left-hand side; $: starts the right-hand side.) Note that the trailing dot on the left-hand side may or may not be necessary. Also note you need a second tab after the right-hand side and the comment (between $3 and dnl).

You'll want to make sure example.com is in your relay-domains file.

Once the domain has been collapsed by the rewrite rule, you can route all mail for the domain to a single user with a virtusertable entry:

@example.com  luser

That should about do it.