How to install sSMTP on Debian 11

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install ssmtp on Debian 11. ssmtp is a mail transfer agent (MTA) that you can use to send emails to a smtp server from your server or computer.

For example, If you want to be notified in real time about tasks on your server via email, then ssmtp is the utility that will make this happen.  The configuration of ssmtp can be done very easily in a few steps we mentioned in this tutorial.

Step 1 - Install ssmtp

In this tutorial we are using debian 11, however the installation command is the same for all debian based operating systems, so to install ssmtp simply run

sudo apt install ssmtp -y

Note: -y is the option that allows you to install the package without having to confirm this installation.

Step 2 - Setup ssmtp.conf

Once you have installed ssmtp package on your system, now you need to configure the configuration file ssmtp.conf with the email credentials that you will be using to send emails. The default ssmtp.conf file looks like this

Notice that all lines are commented out, which means none of this lines are active, you can safely delete all these lines and copy your configuration into the file, not that it changes anything in terms of function but it makes easier for you to read and change config in the future.

sudo nano /etc/ssmtp/ssmtp.conf

To configure ssmtp.conf to send emails, you need to set the following configuration lines

mailhub - The smtp server

hostname - Hostname

AuthUser - Username of the smtp server

AuthPass - Password

UseSTARTTLS - Set this to YES if you want to use the TLS port (587)

FromLineOverride= YES - means the from address won't be generated by the system, for example when you send an email using your email then the email address from where you sent the email will stay the same. Set to NO FromLineOverride=NO if you want the from email address to change automatically.


If you don't know how to setup the ssmtp.conf then use the config above, all you need to do is replace the current credentials with your own smtp credentials. If you want to use an email like Gmail or Outlook to send these emails, then simply use their  smtp config.

Check out how to setup gmail on ssmtp.conf

Once you have configured ssmtp.conf, press CTRL + X to save it.

Step 3 - Send email

Now you need to verify that ssmtp is configured correctly and you can send an actual email. To send an email using ssmtp, run the following command

ssmtp email-address

Note: email-address is the email address where you want to send the email to, replace it with your own and press enter

Next, ssmtp will wait for your input, the input in this case is not the message body but the configuration as shown below

To: email-address
From : email-address
Subject : Subject

Once you type the config as the example above, press enter and write the message content, then you need to press CTRL + D to send the email. And you should receive the email on your inbox. We used gmail as example, and this is how the message looks like

If email is not delivered you may see the error "ssmtp: Cannot open mail:25" This error indicates that ssmtp is trying to connect to port 25. Make sure the mailhub is configured correctly, the cause for this error is when you have an unconfigured mailhub server. For example, when mailhub is using default config on /etc/ssmtp/ssmtp.conf



In this tutorial, we explained step by step how to install ssmtp on Debian 11, how to send an email with ssmtp, and also how to configure ssmtp.conf to work with email service like gmail.