Using a relay host with Sendmail

From TykWiki
Jump to navigationJump to search

This article explains how to configure a relay host with Sendmail. Like everything else involving sendmail, it isn't as simple as it should be.

Configuring sendmail to use a relay host for all outgoing mail

The change involves two steps:

  • You need to add a line to /usr/src/etc/sendmail/
  • Then you need to compile a new and overwrite the existing one.

Make a new .mc file

First make a copy of the default file by running the following commands:

$ sudo cp /usr/src/etc/sendmail/ /usr/src/etc/sendmail/

'Note: If you already have a non-standard .mc file that your current file is built from, you need to add the new line to that .mc file and not a copy of the default .mc file, or you will loose your other changes!

It doesn't matter what you call the new .mc file. Open it up in an editor and add the following lines in the bottom (replacing with your own relay host, of course):


There is a few things worth noting about the way sendmail handles the name of the relay/smart host.

First of all, if you dont fully qualify the hostname by adding the last dot after the hostname, sendmail will loop through all your search domains before trying to resolve the fully qualified name. This means a lot of unneeded DNS queries.

Secondly, if you don't put the hostname in the square brackets, sendmail will first try to find an MX record for the hostname, before falling back to the A record. This, combined with the search domains thing mentioned above, has for some reason led to my sendmail reporting dns lookup failures when trying to resolve the hostname of the relay server, presumably because it tries to resolve a bunch of things that doesn't resolve:

Jul  7 13:37:19 ildipiben sm-mta[27186]: n67BbJvB027184: to=<>, ctladdr=<> (1001/1001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30390,, dsn=4.0.0, stat=Deferred: Name server: host name lookup failure 

Anyway, after adding the SMART_HOST line above to the .mc file, you need to compile the new file:

$ pwd
$ sudo make
rm -f
m4 -D_CF_DIR_=/usr/src/etc/sendmail/../../contrib/sendmail/cf/   /usr/src/etc/sendmail/../../contrib/sendmail/cf/m4/cf.m4 /usr/src/etc/sendmail/ >
chmod 444

The new config file is called and is either in /usr/obj/usr/src/etc/sendmail/ or in /usr/src/etc/sendmail/ (the current directory). Now you just need to copy it to /etc/mail/ overwriting the one currently being used by sendmail, and restart sendmail for the changes to take effect. Remember to backup the current before overwriting it. Then try sending a mail, and check the maillog to see if it used the correct relay server:

$ sudo cp /etc/mail/ /etc/mail/
$ sudo cp /usr/obj/usr/src/etc/sendmail/ /etc/mail/
$ sudo /etc/rc.d/sendmail restart
Stopping sendmail_submit.
$ echo "testing sendmail smart host" | mail -s "testing sendmail smart relay stuff"

I checked /var/log/maillog with tail and found the following line amongst the rest of the normal logging, which tells me that it is now using the relay I specified, and also that it managed to speak TLS with the Postfix relay server:

Jul  7 18:38:45 tempwall sm-mta[90489]: STARTTLS=client,, version=TLSv1/SSLv3, verify=FAIL, cipher=DHE-RSA-AES256-SHA, bits=256/256

--Tykling 16:52, 7 July 2009 (UTC)