How to Install & Configure Sendmail on Ubuntu 18.04 & 16.04 LTS

Sendmail is a common purpose e-mail routing facility used for e-mail transport over the Web. It contains SMTP for the mail-transfer and e-mail delivery. Many of the system administrators preferred to use Sendmail server as MTA than other MTAs. You may also use Sendmail server to send the e-mail through external SMTPservers like Gmail, Amazon SES, MailChimp and many others.

1. Remove Postfix

Postfix is the default SMTP service pre-installed on Ubuntu operating systems. And you’re prepared to make use of Sendmail server in your system.

Initially, remove the present postfix installation on Ubuntu.

sudo systemctl stop postfix
sudo apt remove postfix && apt purge postfix

2. Install Sendmail

If you don’t have installed Sendmail utilizing the following command to install Sendmail with other required packages utilizing yum package manager.

sudo apt install sendmail

3. Configure Sendmail Server

The execute the sendmailconfig command to finish the basic configuration.

sudo sendmailconfig

Choose all choices to ‘Y’ and press enter. Watch for the command end.

Your server is prepared for sending emails. You should use the Linux command line or PHP script to send emails.

4. Receive Incomming Emails

Edit /etc/mail/ file and comment below line to allow receiving an e-mail from anywhere. To comment a line in, simply put dnl keyword at the beginning of the line.


 DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=')dnl


 DAEMON_OPTIONS(`Family=inet,  Name=MSP-v4, Port=submission, M=Ea, Addr=')dnl

Then add your domains to /etc/mail/local-host-names file.

cat /etc/mail/local-host-names

Now use m4 is a macro processor to compile the Sendmail configuration files. m4 is stream-based, that’s, it doesn’t understand about lines.

sudo m4 /etc/mail/ > /etc/mail/

Restart Sendmail service

sudo systemctl restart sendmail

Your system is prepared for incoming emails.

5. Configure Domain-based E-mail Routing

As we learn above that virtusertable file used for aliasing, allowing multiple virtual domains to be hosted on one machine.

  • 1. All emails addressed to domain delivered to [email protected] [email protected]
  • 2. All emails addressed to [email protected] will ahead to local user jack.
    [email protected]  jack
  • 3. All emails addressed to will ahead to domain with corresponding usernames.    %[email protected]
  • 4. All emails addressed to shall be rejected my mail server with acknowledging sender with the message 	 error:nouser User unknown

After making all modifications in virtusertable execute following command to create updated virtusertable.db file containing the new configuration.

sudo makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable

Now restart Sendmail service

sudo /etc/init.d/sendmail restart

Thanks for reading this article. I hope this text will show you how to configure Sendmail on Ubuntu 18.04 & 16.04 LTS systems.

Leave a Reply