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?

3 Answers 3


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:



   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!

  • 2
    With the server's fully-qualified domain name matching exactly to the mail destination's FQDN, one thing to be careful of is applications depending on example.com resolving to localhost once the entry is removed from hosts, since A-record lookups to example.com will start returning the address from DNS. Mar 1, 2011 at 17:55

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

# file containing names of hosts for which we receive email

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:

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .