Sendmail : ignore local delivery

I've a Ubuntu webserver with Sendmail as my MTA

Currently when i email outside my webserver's domain e.g. example.com to something like gmail or any other email outside the example.com domain it works perfectly. I don't want my sendmail daemon to recognize example.com as a local address I want it to send to example.com the same way any other email is sent.

There will never be a case were i will use the local users on the webserver to collect these emails for example.com.

So how can I disable local delivery?


You can do that by removing your domain name from /etc/hosts file. You need to configure senmail to use your domain name (example.com) when sending the emails instead of localhost.

edit /etc/mail/sendmail.mc add the following:

     MASQUERADE_AS(example.com)dnl
     FEATURE(masquerade_envelope)dnl
     FEATURE(masquerade_entire_domain)dnl
     MASQUERADE_DOMAIN(example.com)dnl

before:

   MAILER(smtp)dnl
   MAILER(procmail)dnl
   dnl MAILER(cyrusv2)dnl

type m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf then run /sbin/service sendmail restart

backup everything you edit before any change!

this solution is working fine with me!


Sendmail treats the "w" class as what domains it will attempt local delivery for. The default CentOS configuration includes these lines, for example:

Cwlocalhost
# file containing names of hosts for which we receive email
Fw/etc/mail/local-host-names

This specifies "w" to include the name "localhost" and the contents of the file "/etc/mail/local-host-names". I suspect that you have "example.com" in "/etc/mail/local-host-names", probably set up during the system installation.

You'll want to double-check this, as I don't have a sendmail test system to verify this on so I can't verify this here. Also, it may vary somewhat depending on your exact sendmail installation, which can vary some by distribution or OS.


You can do that by adding rules to ruleset 2. In you sendmail.mc file add the following:

LOCAL_RULE_2
R$* < $=w . > $*          $#esmtp $@[MX server for example.com] $: $1 < @ $2 > $3

Remember that the left and the right hand side of the rule are separated via tabs, so do not copy paste. Then build your sendmail.cf from your sendmail.mc, restart sendmail and test.

You can use the bestmx map if you do not want to hardcode the MX server name between the brackets.