How to Install and Setup Sendmail on Debian 10

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

How to install and configure Sendmail on Debian 10 for sending emails using a email server which routes or relays the mail delivery.

Sendmail is a opensource Mail Transfer Agent (MTA) which is used to route email using server or by using shell commands. You can also configure SMTP using Sendmail.

In this guide you are going to learn how to install and setup Sendmail on Debian 10. Also you will setup SMTP and configure it with PHP. This setup is tested on Google Cloud

Update Server Packages

SSH inside your server and update the packages to it’s latest version.

sudo apt update
sudo apt upgrade

Install Sendmail

Sendmail is available in the Debian repository, so you can directly install using apt install command.

sudo apt install sendmail

Configure Hostname

Edit the /etc/hosts file and add your hostname.

sudo nano /etc/hosts

On the line starting with, add the hostname to the end as it looks below. This should be on a single line. localhost hostname

Replace hostname with your hostname.

Configure SMTP

Create new directory inside /etc/mail for SMTP configurations.

sudo mkdir /etc/mail/authinfo

Setup correct permissions.

sudo chmod -R 700 /etc/mail/authinfo

Create a new file for your SMTP authentication inside the newly created directory.

cd /etc/mail/authinfo
sudo nano smtp-auth

Paste the following line and replace the email-address with your login email and password with your password.

AuthInfo: "U:root" "I:email-address" "P:password"

Hit CRTL + X followed by Y and ENTER to save and exit the file.

Create a hash database map for the above created authentication.

sudo makemap hash smtp-auth < smtp-auth

Configure SMTP

Navigate to the sendmail configuration directory and edit the file.

cd /etc/mail
sudo nano

Add the below configurations right after the MAILER _DEFINITIONS line.

Replace smtp-host with your SMTP hostname.

define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/smtp-auth.db')dnl

The configuration should look like the same as the below screenshot.

SMTP configuration

Now save the file and exit the editor.

Rebuild Sendmail Configuration

Once the configuration is done you need to rebuild the Sendmail configuration using the make command.

cd /etc/mail

Once the configuration is rebuilt you need to restart Sendmail

Restart Sendmail

Restart Sendmail using the following command.

sudo /etc/init.d/sendmail restart

Now you can send emails using SMTP.

Additional Configurations

Configuration with PHP

To use Sendmail with PHP you need to ad sendmail path in your php.ini file.

sudo nano /etc/php/version/fpm-or-apache2/php.ini

To the bottom of the file add the following.

sendmail_path= /usr/sbin/sendmail -t -i

Restart Apache or PHP-FPM for the changes to take effect.

sudo service apache2 restart


sudo service php8.0-fpm restart

Sendmail SMTP Configuration without Auth

Incase if you have whitelisted your server IP for SMTP and you can send emails without authentication you can follow the below method.

You don’t need to create the smtp-auth file that we created above.

You can directly edit the file and make the following changes.

cd /etc/mail
sudo nano

Add the below configurations to the last.

Replace smtp-host with your SMTP hostname.

define(`RELAY_MAILER', `esmtp')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

Save the file, rebuild configuration and restart Sendmail.

cd /etc/mail
sudo /etc/init.d/sendmail restart


Now you have learned how to install and configure Sendmail to relay using SMTP on Debian 10.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.


  1. Hi, thanks for the tutorial. I have a trouble, sendmail doesn’t send tha mail with no errors.

  2. Daniel Kohn Reply

    Now that GMAIL has shut down SMTP, can you come up with instructions to transition sendmail so it works with a more secure protocol?

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.