Relay mail with cron jobs and Sendmail

Q I'm currently running Fedora on my desktop and was wondering if it's possible to relay mail sent via Cron jobs etc. through my mail server running Sendmail. It would save me having to run another instance of Sendmail on my desktop.

A Although there is next to no configuration required to setup Sendmail or Postfix on Fedora, you can use ESMTP or SSMTP to relay your desktop's mail through an external mail server. I've used SSMTP in the past, but it appears that only ESMTP is currently available via Yum. To install, run

yum install esmtp
cat > /etc/esmtprc << "EOF"
hostname = mailserver:25
mda "/usr/bin/procmail -d %T"
EOF

This basic configuration will route mail through a server named mailserver, on port 25. You can man esmtp and man esmtprc for more information on esmtp and the configuration file. If Sendmail is currently your default MTA (run alternatives --display mta to check), you can issue the following to switch ESMTP to the default:

alternatives --config mta

This will bring up a basic menu that allows you to switch the default MTA. Finally, if you intend to relay mail through your Sendmail server destined for a mailbox that's not local (ie redirecting Cron output to an @gmail. com address), ensure you configure /etc/mail/access on the Sendmail server to permit your desktop to relay through it. As I've suggested, SSMTP is another option that can be used instead of ESMTP. It's not available via Yum, so you'll need to install it manually. Here is a basic outline of how to get it up and running:

cd /root
wget ftp://ftp.debian.org/debian/pool/main/s/ssmtp/ssmtp_2.61.orig.tar.gz
tar -xzvf ssmtp_2.61.orig.tar.gz
cd ssmtp_2.61
make
make install

This will prompt you for a few pieces of information and will install the SSMTP binary to /usr/local/sbin and ssmtp.conf to /usr/local/etc/ssmtp/ssmtp.conf. The mail line that needs to be adjusted in ssmtp.conf is mailhub=mail', where 'mail' is your Sendmail server's hostname. For more information, run man ssmtp and view the default ssmtp.conf configuration file in the ssmtp_2.61 source directory. As this is a manual install not using rpm, you will need to use the alternatives command to add SSMTP to the alternatives system. This can be done with

alternatives --install /usr/sbin/sendmail mta /usr/local/sbin/ssmtp 10

Finally, ensure that SSMTP is the default MTA:

alternatives --config mta

Again, this command will ask which MTA to use, and don't forget that if you plan on relaying to externaladdresses, you should configure the Sendmail server to permit relaying from your desktop's IP address.

Back to the list