Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to get sendmail to transfer mails to the servers specified in the MX records so when the server sends an email to I want it to skip localhost and go straight to gmail.

I've gone over the sendmail docs, but don't quite understand how to account for my situation. Essentially my server's hostname is '' but when I send an email to '' it ends up in the local mail spool.

When I run sendmail in debug mode:

sendmail -bt
> $=w

I get:

So, it is intercepting all outgoing mail to I dont want it to arrive at localhost. I want it to go to gmail servers.

All mail bound for other addresses works fine. I also have sendmail configured to use DKIM.

I've added a record to mailertable (and rebuilt the mailertable.db and recompiled the mc>cf file) but I'm not sure if that's what I need to do or if I am doing it correctly. esmtp:[]

How do I get it to allow mail bound for to leave the server?

ADDITIONAL INFO: Here is my file:


VERSIONID(`setup for linux')dnl

define(`confDEF_USER_ID', ``8:12'')dnl

define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST', `True')dnl
define(`confDONT_PROBE_INTERFACES', `True')dnl
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/mail/statistics')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl

define(`confTO_IDENT', `0')dnl

FEATURE(`no_default_msa', `dnl')dnl
FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl

FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl






INPUT_MAIL_FILTER(`opendkim', `S=inet:8891@localhost')

share|improve this question
Your question's logic is completely flawed. It boils down to "I don't want to use Sendmail to send my mail. How do I reconfigure Sendmail with extra configuration to send mail exactly how Sendmail sends mail by default?" Answer: leave it alone. Either your question needs to be entirely re-worded to get across what you're actually attempting to do, or you need to stop meddling in your server's config and let it do what it does without breaking it. –  Sammitch Sep 3 '13 at 22:25
okay then. alternatively, explain to me what i would do if i only want to send email from the server and not to it. –  Octopus Sep 4 '13 at 5:17

6 Answers 6

Change the server's hostname. There's no valid reason for a hostname to ever be equal to a naked domain name.

share|improve this answer
yes, i tried that, even when i set the hostname to sendmail wants to keep everything bound for, and localhost. i can see that when i run sendmail in debug mode and type $=w. i reworded the question slightlty to explain. –  Octopus Sep 4 '13 at 5:18

Here's my understanding of your question:

  1. You installed Sendmail so that you could use it to send email from your website.

  2. You configured Sendmail to be the authoritative email server for your public DNS namespace.

  3. You don't want Sendmail to be authoritative for your public DNS namespace. You want email sent to your public DNS namespace to be sent to your Google hosted email.

Solution: reconfigure Sendmail so that it is not authoritative for your public DNS namespace.

share|improve this answer
My question is about sendmail configuration. Can your answer be more specific than "reconfigure sendmail"? –  Octopus Sep 4 '13 at 15:56
up vote 3 down vote accepted

I finally found a rather comprehensive solution here. To summarize, there are a number of options (most of which have been mentioned in other answers, but for whatever reasons didn't work in my particular scenario).

Option 1: remove the entry from /etc/mail/local-host-names

for me this file was already empty

Option 2: remove any LOCAL_DOMAIN entry in the mc file

i had none

Option 3: tell sendmail not to probe interfaces

define(`confDONT_PROBE_INTERFACES', `true')dnl

in my case this was set, yet the problematic host was still present in class w of sendmail

Option 4: rename the server. the external link provided above even specifically says, "If I want to remove from class w, I could rename the server to,,, for example."

for me this wasn't sufficient. with the host named, sendmails class w still contained BOTH AND (even after a reboot)

Option 5: THIS IS WHAT WORKED FOR ME add a LOCAL_RULE_0 to the sendmail mc file

R$* < > $*  <tab>$#esmtp $@ $: $1<>$2

this needs to go at the end of the file and <tab> needs to be an actual tab character

share|improve this answer
I would go with option 5 and using a bestmx map to make it generic. –  adamo Sep 5 '13 at 13:19
This one works perfectly. Thanks for Octopus LOCAL_RULESETS LOCAL_RULE_0 R$* < > $* <tab>$#esmtp $@ $: $1<>$2 this needs to go at the end of the file and <tab> actually you have to use tab key instead of the code. –  Vinodh Kumar Feb 2 at 11:54

I'm not too experienced with sendmail configuration, but I feel it should be doing the right thing with respect to MX records. However, I imagine it might be possible that in the precedence of DNS lookups, sendmail is first consulting the local hosts file /etc/hosts on most unix based operating systems before using it's DNS servers. If that's the case, and there's an entry in the hosts file that refers to your machine as if you set that as the hostname, that could be whats going on. You can edit the hosts file to suit your needs in this particular case by modifying the entries or adding new ones.

Or you can configure sendmail to ignore the local system hosts file when resolving urls. I'm not sure how to do that.

share|improve this answer

1) Sendmail automatically fills list of local email domains ($=w).

You cant turn it off using the following line in your


You can add local emails "manually" in /etc/mail/local-host-names file.
(It requires HUPing or restarting sendmail daemon after)

2) Sendmail may add (autoconfigured) "this host email name" ($j) to list of local email domains.

You may define "this host email name"


3) mailertable is NOT consultede for deliveries to domains listed in $=w.

share|improve this answer
but define(confDONT_PROBE_INTERFACES',True') is already (and always has been) enabled –  Octopus Sep 4 '13 at 15:24
So your case may be covered by option 2. –  Andrzej A. Filip Sep 4 '13 at 22:38
These are all good suggestions that Ive fully explored, but I believe that option 2 is the same as adding hosts to the local-host-names file. in this case i want to EXCLUDE a host not INCLUDE one. –  Octopus Sep 4 '13 at 23:22

The code that's sending the mail, are you using a full email address, or are you just having the server mail it out via a local account? Because:

This is telling sendmail to deliver all mail to users@localhost.localdomain locally


And this is telling sendmail to rewrite the domains in local addresses to, but does not alter the local delivery.


okay then. alternatively, explain to me what i would do if i only want to send email from the server and not to it.

Step 1: Go back to the default config.
Step 2: Use the default config.

share|improve this answer
Yes thats right but, I'm sending to The default config has the exact same problems I outlined in the question. –  Octopus Sep 4 '13 at 17:07

Your Answer


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.