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/sendmail.mc file and comment below line to allow receiving an e-mail from anywhere. To comment a line in sendmail.mc, simply put dnl keyword at the beginning of the line.

dnl

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

dnl

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

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

cat /etc/mail/local-host-names

webtips4u.com
mail.webtips4u.com
localhost
localhost.localdomain

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/sendmail.mc > /etc/mail/sendmail.cf

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 @example.com domain delivered to [email protected]
    @example.com [email protected]
    
  • 2. All emails addressed to [email protected] will ahead to local user jack.
    [email protected]  jack
    
  • 3. All emails addressed to @mydomain.com will ahead to domain @otherdomain.com with corresponding usernames.
    @mydomain.com    %[email protected]
    
  • 4. All emails addressed to @otherdomain.com shall be rejected my mail server with acknowledging sender with the message
    @otherdomain.com 	 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