How do I configure sendmail to send mail via MX record and not to localhost?

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 [email protected] 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 'www.domain.com' but when I send an email to '[email protected]' it ends up in the local mail spool.

When I run sendmail in debug mode:

sendmail -bt
> $=w

I get:

www.domain.com
www.domain.com.
domain.com
localhost
[54.245.___.___] 

So, it is intercepting all outgoing mail to domain.com. 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.

domain.com esmtp:[aspmx.l.google.com]

How do I get it to allow mail bound for [email protected] to leave the server?

ADDITIONAL INFO: Here is my sendmail.mc file:

divert(-1)dnl

include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`setup for linux')dnl
OSTYPE(`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(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl

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

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

FEATURE(`accept_unresolvable_domains')dnl
FEATURE(`relay_based_on_MX')dnl
FEATURE(`relay_entire_domain')dnl

LOCAL_DOMAIN(`localhost.localdomain')dnl

MASQUERADE_AS(`domain.com')dnl
MASQUERADE_DOMAIN(`localhost.localdomain')dnl

EXPOSED_USER(`root')dnl

FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl

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

MAILER(smtp)dnl
MAILER(procmail)dnl

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 whipple.org from class w, I could rename the server to frodo.whipple.org, www.whipple.org, elvis.whipple.org, for example."

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

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

LOCAL_RULESETS
LOCAL_RULE_0
R$* < @domain.com. > $*  <tab>$#esmtp $@ mail.domain.com $: $1<@domain.com.>$2

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


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


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.