Monday, August 13, 2012

Configuring sendmail as a backup relay

SkyHi @ Monday, August 13, 2012

The relay_based_on_MX feature is not needed. 

1) Add an entry to your mailertable file:    esmtp:[ip of primary mail server]

2) Then add to /etc/mail/relay-domains.

Whatever you do... do NOT add to /etc/mail/local-host-names.

3) Rebuild the mailertable database and then restart sendmail

FWIW: There is a second option (this is what I do). Use the DSMTP mailer.

1) add to /etc/mail/mailertable:    dsmtp:[ip of primary mail server]

2) add my to /etc/mail/relay-domains.

3) Rebuild the mailertable database and then restart sendmail
makemap hash /etc/mail/mailertable.db < /etc/mail/mailertable
m4 /etc/mail/ > /etc/mail/
kill -HUP `head -1 /var/run/`

The difference is now sendmail will queue all e-mail for
instead of trying to deliver to the primary (which is down). Plus the normal
sendmail queue runs will be ignored for e-mails that were queued with the
DSMTP mailer. i.e. No DSN's are issued should your primary be down for an
extended amount of time.

There is an added step to using the DSMTP mailer. To release the queued
e-mail from the backup server, you will need to issue an ETRN against the
backup mailer server from the primary when its backup and running. I simply
have a cronjob do this once an hour. Example:

Using the supplied script supplied with the sendmail source... from
the primary:

We do exactly this.
You need to make entries in two configuration files.
First, enter the domains you are going to relay for in /etc/mail/relay-domains, one per line. Include any variations.
Second, in /etc/mail/mailertable, you have to tell sendmail what to do with mail destined for that domain.
Remember to run make in /etc/mail so that the changes to mailertable take effect.
Note that if you don't put an entry in mailertable for a domain, it will consult DNS and try to send to a 'better' MX; if DNS has nothing of use, it will try to deliver the mail locally (and fail, unless you've doctored/etc/mail/local-host-names).