Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 8:48
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.