TheGeekery

The Usual Tech Ramblings

Mail Relaying in Sendmail

I’ve always been in favor of removing the standard Sendmail install on most Linux boxes, in favor of Postfix. I’ve found it easier to use, and easier to configure. Having a simple configuration file that doesn’t need compiling is always helpful too. However, in some cases, you really don’t like to touch the delicate balance of an ancient server, in fear of it falling over in a spectacular death.

Due to the nature of a lot of viruses, our firewall blocks outbound SMTP, with the exception of a few hosts. This allows for services to use the server as a mail relay, whilst not allowing infected clients to send bad emails. Due to this, I had to figure out how to reconfigure sendmail on one of our servers to use our postfix based server as a mail relay. This actually turns out to be relatively easy, a single line in the /etc/mail/sendmail.mc file. The bit that caught me was getting it to work.

RedHat is nice, in that they supply a make command in the /etc/mail directory to build new configurations. However, for some reason, the default install of sendmail is missing some critical files that allow the rebuild of the configs to work. The first step to setting up the relaying was to add the line:

1
DEFINE(`SMART_HOST',`my.relay.host')

This was added into the /etc/mail/sendmail.mc file. Then the idea is you’re supposed to be able to execute:

1
make -C /etc/mail

This spewed out some data about it processing the directories. I then recycled sendmail. I gave the new setup a quick test, and found it was still trying to direct send. I verified the files, and it was configured right. However, I noticed something odd. Using ls -lt I found the sendmail.cf file (the compiled configuration file) had not been updated. This was odd, as it should have built it.

Having had experience with modifying the sendmail configurations before, I knew the make command was simply issuing an m4 command to compile the configurations. On a hunch, I tried running the command myself:

1
m4 sendmail.mc > sendmail.cf

This is where the hint of the issue came in…

1
Cannot open /usr/share/sendmail-cf/m4/cf.m4

So I was missing files required to build the new configuration files. A quick google search showed I needed to have the sendmail-cf package installed. As RedHat 9 is pretty old, I didn’t expect the RedHat FTP servers to still hold the files, so I hit RPMFind, and searched for sendmail-cf. A handful of results returned, but I found the one specifically for RedHat9.

After downloading the RPM file, and installing it using rpm -Uvh file I was then able to execute the make command as I had done before, but this time with a little more success (the files updated). Now it was time to restart sendmail again… This wasn’t as successful….

1
2
sendmail[24223]: NOQUEUE: SYSERR(root): No local mailer defined
sendmail[24223]: NOQUEUE: SYSERR(root): QueueDirectory (Q) option must be set

That’s not right. So a quick look in the sendmail.mc file again, I found that the local delivery option was not set, so I added the following line:

1
MAILER(local)

Then rebuilt the configurations using the make command again, and restarted Sendmail. This time with some success. I then tested the connection, ensuring that it relayed through the remote server…

1
2
3
4
sendmail[24468]: l7FFWqWF024468: from=jon@netdork, size=45, class=0, nrcpts=1, msgid=<20070815
1533.l7FFWqWF024468@origsmtp_server>, proto=SMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
sendmail[24472]: l7FFWqWF024468: to=jon@netdork.net, delay=00:00:13, xdelay=00:00:01, mailer=relay, pri=300
15, relay=my.relay.host [172.16.10.5], dsn=2.0.0, stat=Sent (Ok: queued as A979D6BCB4)

Now the server is behaving as I need it to.

Comments