3

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.

Rup
  • 255
  • 5
  • 15
  • We eventually gave up on sendmail and built our own solution to do this on top of an open-source C# SMTP server. I can't believe this isn't possible with sendmail, though. – Rup Sep 17 '10 at 08:48

1 Answers1

3

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.

Daniel S. Sterling
  • 1,584
  • 2
  • 11
  • 13
  • That's great, thanks - I haven't had a chance to go back and test this yet but it sounds good. Do I need to add anything to local-domains too or should the rewrite rule / relay domains sort that out? – Rup Jan 24 '11 at 12:09
  • What's the need for the "\tdnl" at the end at all? With them, I can see a tab at EOL and an additional empty line in the `.cf` file, that's all... – Mikhail T. Dec 17 '21 at 19:01
  • With or without the "\tdnl" this answer does not work for me -- the FOO@SUB.example.com is _not_ rewritten into FOO@example.com, and the special rules for the example.com (it is one of the `local-host-names` here) are consequently ignored... – Mikhail T. Dec 20 '21 at 20:22