How to Install Sendmail on Debian

Sendmail is a MTA (Mail Transfer Agent) server used for transferring email from between different hosts. Sendmail uses SMTP (Simple Mail Transfer Protocol) protocol. Most of the system administrators preferred to use Sendmail server as MTA than other MTAs. This tutorial helps you to Install Sendmail on Debian 9 (Stretch) Linux system.

1. Install Sendmail

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

sudo apt update
sudo apt install sendmail sendmail-cf m4

2. Configure Sendmail Server

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

sudo sendmailconfig

Select all options to ‘Y’ and press enter. Wait for the command finish.

Your server is ready for sending emails. You can 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 email from anywhere. To comment a line in sendmail.mc, just put dnl keyword at the start 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 domain names to /etc/mail/local-host-names file.

cat /etc/mail/local-host-names

sisrv.net
mail.sisrv.net
localhost
localhost.localdomain

Now use m4 is a macro processor to compile the Sendmail configuration files. m4 is stream-based, that is, 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 ready for incoming emails.

4. Configure Domain-based E-mail Routing

As we read 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 support@mydomain.com
    @example.com support@mydomain.com
  • 2. All emails addressed to support@mydomain.com will forward to local user tim.
    support@mydomain.com  tim
  • 3. All emails addressed to @mydomain.com will forward to domain @otherdomain.com with corresponding usernames.
    @mydomain.com    %1@otherdomain.com
  • 4. All emails addressed to @otherdomain.com will be rejected my mail server with acknowledging sender with the message
    @otherdomain.com 	 error:nouser User unknown

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

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

Also make sure 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
Change sender name using sendmail

You can change the senders name by editing DM macro in /etc/mail/sendmail.cf

# Masquerade as (DM): #
# #
# If you wish to have mail appear to be from some host or location other than the loacl host, set macro M to the name you wish to masquerade as. This is also know as site hiding and was set using the DY macro in previous releases of hp-ux.

# who I masquerade as (null for no masquerading) (see also $=M)
DMsisrv.net

 

Thanks for reading and I hope this article will help you to configure Sendmail on Debian system.

  • sendmail, sendmail debian install, restart sendmail, install sendmail
  • 20 istifadəçi bunu faydalı hesab edir
Bu cavab sizə kömək etdi?

Uyğun məqalələr

How to Set Up a Mac for Your Kids

Providing children with access to a computer and the internet is increasingly important, but so...

How to Get Help With a Command from the Linux Terminal

Whether you’re an inexperienced terminal user or a grizzled veteran, you won’t always know the...

How to change the ssh port on Linux

To Change the SSH Port for Linux Server Connect to your server via SSH Switch to the root...

How To Install screenFetch in Linux

If you've browsed Linux groups on social media, you've probably seen a lot of screenshots that...

Static IP vs. Dynamic IP Address

A static IP address is one that remains fixed and never changes. The PC always sees the same...

Powered by WHMCompleteSolution