10

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 me@domain.com 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 'me@domain.com' 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 users@domain.com 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
Octopus
  • 359
  • 1
  • 3
  • 19
  • 1
    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 03 '13 at 22:25
  • 2
    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 04 '13 at 05:17

6 Answers6

10

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

Octopus
  • 359
  • 1
  • 3
  • 19
  • I would go with option 5 and using a `bestmx` map to make it generic. – adamo Sep 05 '13 at 13:19
  • 1
    This one works perfectly. Thanks for Octopus LOCAL_RULESETS LOCAL_RULE_0 R$* < @domain.com. > $* $#esmtp $@ mail.domain.com $: $1<@domain.com.>$2 this needs to go at the end of the file and actually you have to use tab key instead of the code. – Vinodh Kumar Feb 02 '15 at 11:54
  • #1 seemed to work for me – luky Aug 30 '20 at 17:00
  • Brilliant, nothing else helped! This was it. Thank you – sebisnow Jan 10 '22 at 19:14
8

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

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • yes, i tried that, even when i set the hostname to www.domain.com sendmail wants to keep everything bound for www.domain.com, domain.com 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 04 '13 at 05:18
3

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.

joeqwerty
  • 109,901
  • 6
  • 81
  • 172
  • 4
    My question is about sendmail configuration. Can your answer be more specific than "reconfigure sendmail"? – Octopus Sep 04 '13 at 15:56
0

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 domain.com 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.

inetplumber
  • 680
  • 4
  • 9
0

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

You cant turn it off using the following line in your sendmail.mc:

define(`confDONT_PROBE_INTERFACES',`True')

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"

define(`confDOMAIN_NAME',`hostname.example.net')

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

AnFi
  • 6,103
  • 1
  • 14
  • 27
  • but define(`confDONT_PROBE_INTERFACES',`True') is already (and always has been) enabled – Octopus Sep 04 '13 at 15:24
  • So your case may be covered by option 2. – AnFi Sep 04 '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 04 '13 at 23:22
0

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

LOCAL_DOMAIN(`localhost.localdomain')dnl

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

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

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.

Sammitch
  • 2,111
  • 1
  • 21
  • 35
  • Yes thats right but, I'm sending to user@domain.com. The default config has the exact same problems I outlined in the question. – Octopus Sep 04 '13 at 17:07