Linux – How to configure sendmail to relay through a specific server

linuxsendmail

I have a tiny home server setup behind my cable modem (bresnan communications). I want to be able for this box to send out email (not receive) for notifications and whatnot.

What I have already done:

  • I have installed and configured sendmail.
  • I have added mail.bresnan.net as my SMART_HOST directive.

What I belive the problem is

When I attempt to send an email I get the following in my mail log:

Dec 22 10:24:17 batcave sendmail[1530]: oBMHOHrs001530: from=aburns, 
  size=140, class=0, nrcpts=1, 
  msgid=<201012221724.oBMHOHrs001530@bresnan.net>, 
  relay=aburns@localhost
Dec 22 10:24:17 batcave sm-mta[1531]: oBMHOHWZ001531: from=<aburns@bresnan.net>, 
  size=397, class=0, nrcpts=1,
  msgid=<201012221724.oBMHOHrs001530@bresnan.net>,
  proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Dec 22 10:24:17 batcave sendmail[1530]: oBMHOHrs001530:
  to=<my@work-address.com>, ctladdr=aburns (1000/1000),
  delay=00:00:00, xdelay=00:00:00, mailer=relay,
  pri=30140, relay=[127.0.0.1] [127.0.0.1],
  dsn=2.0.0, stat=Sent (oBMHOHWZ001531 Message accepted for delivery)
Dec 22 10:24:18 batcave sm-mta[1517]: oBMH9mVv001357:
  to=<my@work-address.com>, ctladdr=<aburns@bresnan.net>
  (1000/1000), delay=00:14:30, xdelay=00:00:42, mailer=relay,
  pri=300339, relay=pmx0.bresnan.net. [69.145.248.1],
  dsn=4.0.0, stat=Deferred: Connection timed out with pmx0.bresnan.net.

You can see where the message is accepted for delivery by my sendmail server, then where it attempts to hand off to bresnan's server and it timesout.

This is where my question is. Asstute readers will notice that pmx0.bresnan.net is not what I have my SMART_HOST directive set as. This is the (outside?) MX server for the bresnan.com/net domain. Apparently bresnan has their network configured so that you can not access this server from within their own network and instead must use the mail.bresnan.net server (which I can connect to). The problem is that I don't know how to tell sendmail to use this server and not the domain.

What I have tried

  • Setting a hosts entry so that the pmx0 server points to the mail IP address. This doesn't work, which makes sense as sendmail is obviously doing an MX query to find the server which returns the IP so there is never a need to do a 'normal' DNS resolve so the hosts file never gets involved.

The Fix (for all outgoing mail):

Again, props goes to webmin (see note below) for helping me learn this. If you enter your smarthost with square brackets that instructs sendmail to not do an MX lookup, so: define('SMART_HOST','[69.145.248.18]') (Fix the quotes->backticks) actually works without a mailer table.

The Fix (for specific domains):

As pointed out below setting up a mailertable is required. However, as pointed out in the man page, this feature also needs to be enabled in your sendmail.mc file.

Also note that the mailer route does not force sendmail to use the specified server for all operations, it is based on the recipient's address. This is actually OK for me as I only need to send to a few domains (gmail, google hosted, and my work).

Summary:

  • Add FEATURE('mailertable') to your sendmail.mc file. (note that the first quote should be a backtick.
  • Create your /etc/mail/mailertable file (See man page)
  • Create a mapfile: sudo makemap hash /etc/mail/mailertable.db < /etc/mail/mailertable
  • Rebuild your configs make -C /etc/mail
  • Restart sendmail: service sendmail restart

NOTE: I highly recommend using WebMin to edit/rebuild these files. Without it I would have gone crazy trying to figure out why my mailertable file was being ignored.

Best Answer

You can get around the MX lookup by adding a short entry into your sendmail /etc/mail/mailertable file.

The contents of the file should probably have a single line like:

bresnan.net       esmtp:[69.145.248.18]

Save the file and restart sendmail (or rebuild your sendmail.cf if it must be done manually).

Related Topic