Learn How to Install & Configure Sendmail on Debian 9 (Stretch)

Sendmail is a MTA (Mail Transfer Agent) server used for transferring e-mail from between completely different hosts. Sendmail makes use of SMTP protocol. Many of the system administrators most well-liked to make use of Sendmail server as MTA than other MTAs. This tutorial lets you Install Sendmail on Debian 9 (Stretch) Linux system.

1. Install Sendmail

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

sudo apt update
sudo apt install sendmail sendmail-cf m4

2. Configure Sendmail Server

Now, execute the sendmailconfig command to finish the basic configuration.

sudo sendmailconfig

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

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

3. 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

tecadmin.net
mail.tecadmin.net
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.

4. Configure Domain-based E-mail Routing

As we learn above that virtusertable file used for aliasing, permitting 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 the next command to create an updated virtusertable.db file containing the new configuration.

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

Additionally ensure that the following entry is added in sendmail.mc file.

FEATURE(`virtusertable')

Add entry if not available and compile configuration file

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Now restart Sendmail service

sudo systemctl restart sendmail

Thanks for reading this article. I hope this article will show you how to to Install & configure Sendmail on Debian 9 (Stretch) system.

Leave a Reply