How to setup an E-Mail Relay Host with Sendmail?

What are the basic steps for working with sendmail configuration file?

  1. Edit the /etc/mail/
  2. Regenerate the /etc/mail/ from the /etc/mail/ file
    1. sudo chmod 666 /etc/mail/
    2. sudo m4 /etc/mail/ > /etc/mail/
    3. sudo chmod 644 /etc/mail/
  3. Restart sendmail

How can we regenerate /etc/mail/ from /etc/mail/

sudo chmod 666 /etc/mail/
sudo m4 /etc/mail/ > /etc/mail/ 
sudo chmod 644 /etc/mail/

How can we restart sendmail?

sudo /etc/init.d/sendmail restart

How can we restart Sendmail in debug mode?

sudo /etc/init.d/sendmail restart -bD -O LogLevel=20 -X /tmp/sendmail.log

How can we verify your configuration by generating a deliverability report?

sudo sendmail -bv

In this report, look for the following output: deliverable: mailer awsemail, host, user

How can we to send a test email?

sudo /usr/bin/sendmail -f

Type your message and put a dot on a single line by itself or press CTRL+D. We can also create a test file to_internet:

Subject: Ein Test

Dies ist ein Header Test
(empty line)

and then do:

cat to_internet | /usr/lib/sendmail -bm -t -v
/usr/lib/sendmail -vt

How can we show the delivery agent (debug)?

/usr/lib/sendmail -d0.12 -bt < /dev/null

How can we show macros without $u, $M which will be set when mail is already delivered (debug)?

/usr/lib/sendmail -d35.9 -bt

How can we show sendmail queue?

/usr/lib/sendmail -bp

How can we test the MX-Record readed by Sendmail from DNS?

/usr/lib/sendmail -bt

How can we configure smart host?

Edit /etc/mail/


How can we configure sendmail to relay mail through another server?

  1. Open up /etc/mail/
  2. Search for SMART_HOST
  3. Remove the dnl (delete through newline) prefix.
  4. Save the file
  5. Regenerate the file.

If you do not use m4, open up /etc/mail/, search for DS, and update it to:


What is the purpose of mailertable?

mailertable allows you to route or deliver mail to different hosts. Edit /etc/mail/ to include:


and edit /etc/mail/mailertable to include:


Now build database version of the mailertable is built using:

makemap hash /etc/mail/mailertable

Other useful debugging commands:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License