Sendmail is a popular Mail Transfer Agent (MTA) and it is the default MTA on Red hat Linux Enterprise (RHEL). Typically, within enterprises, you will need a Mail User Agent (MUA), an MTA and an SMTP Relay to send emails (outbound) from the Linux command-line or shell scripts.
So, let’s assume that your Mail Administrator provides you IP addresses of primary (192.168.1.1) and secondary (192.168.2.2) SMTP Relay hosts. Given below are steps to configure sendmail (on RHEL 4) to use the SMTP relays to send email (you must use root user’s privileges):
STEP 1: Verify sendmail packages
In order to configure sendmail, you will require the sendmail and sendmail-cf packages. Given below is an example of how to check for these packages:
rpm -qa | grep sendmail sendmail-8.13.1-3.3.el4 sendmail-cf-8.13.1-3.3.el4
STEP 2: Modify sendmail.mc
Do not edit /etc/mail/sendmail.cf. Instead, you must edit /etc/mail/sendmail.mc (more readable than sendmail.cf) and use the m4 macro processor to generate sendmail.cf.
Edit /etc/mail/sendmail.mc and add the following line:
(1) Pay attention to the quotes. Do not prefix the above by the letters dnl as dnl (delete to new line) denotes a comment in sendmail.mc
(2) If you wish to configure only 1 SMTP relay host (e.g. 192.168.1.1), then add the following:
STEP 3: Start/Restart sendmail
When sendmail is started (if not running) or restarted (if running), then the sendmail.mc file will be processed by the m4 macro processor and a corresponding sendmail.cf will be generated. On RHEL, you may start sendmail as follows:
/sbin/service sendmail start
STEP 4: Use an MUA to test outbound mail
In order to test your sendmail configuration and the SMTP relays, use an MUA to send emails. Given below is an example that uses mutt to send emails:
mutt -s "test email" email@example.com < /dev/null