Linux - How to install and configure sSMTP, a simpler alternative to Postfix and Sendmail A brief tutorial explaining how to setup sSMTP, a simple Linux service to send e-mail through your CentOS machine

Linux - Come inviare E-Mail con sSMTP (con configurazioni-tipo per GMail, Aruba e Yahoo)

If you stumbled upon this post it means that you want to find a way to send e-mails from your Linux server and you're looking for a simpler alternative to configure than Sendmail and Postfix mail services. This is a rather common need for those who run simple sites / blog / services in a LAMP (Linux, Apache, MySQL, PHP)  environment and need to set the value of the sendmail_path  property in the php.ini file.

The alternative in question is called sSMTP and is a minimalistic Mail Transfer Agent (MTA) which can be used to send outgoing mail from your Linux system. That said, the choice is yours: if you still prefer to install the real deal, read how to install Postfix on CentOS; otherwise, keep reading.

Setup

Let's see how to install sSMTP and use it in the correct way with the main SMTP e-mail service providers used in Italy, that is GMail and Aruba. The steps shown in this post are valid for a RedHat / CentOS 7 / Fedora distribution, but can be also used on any other Linux distribution without problems.

The first thing we have to do is to install the ssmtp package within our Linux server, by executing the following Terminal command - depending on your Linux distribution:

RedHat, CentOS7, Fedora

If you receive a "Package ssmtp is not available" error, you'll need to install EPEL on your machine with the following command:

Once done, you'll be able to install ssmtp using the above command.

Ubuntu, Debian

Configuration

Once we've got it installed, sSMTP will create his two configuration files in the  /etc/ssmtp/  folder:

The first file, which we need to setup properly, is meant to contain the connection info to the remove SMTP server: the second file, which is rather optional, allows to setup some aliases for the local users: these aliases, if present, will replace the SMTP parameters specified in the first file.

Both files are well-documented by the inline comments and rather simple to configure: in the following paragraphs we'll see some examples to configure the service for some SMTP providers such a GMail, Aruba and Yahoo.

GMail

Here's a   /etc/ssmtp/ssmtp.conf  sample file that we can use to configure sSMTP with the [email protected] GMail account:

If we also want to configure the   /etc/ssmtp/revaliases  file, here's how we can give a valid alias to the root user:

Aruba

Here's a   /etc/ssmtp/ssmtp.conf  sample file that we can use to configure sSMTP with the [email protected] account, for SSL and non-SSL mail delivery servers provided by Aruba:

SSL (TCP port 465)

NON-SSL (TCP port 25)

And here's the corresponding  /etc/ssmtp/revaliases content in case we want to configure an alias for root:

Yahoo.it

File /etc/ssmtp/ssmtp.conf :

File /etc/ssmtp/revaliases :

Test run

Once done, it is advisable to perform a rapid test to confirm that everything is properly working. The easiest way to check that is to run the ssmtp command within a terminal shell: to do so, we can either use interactive mode - writing the message immediately before sending it - or send a previously prepared message saved in a text file.

Let's see them both:

Interactive mode

Immediately after executing the above command, we'll get the chance to write our message in the following way:

We need to pay attention to leave an empty line between the Subject and the body of the message, otherwise the e-mail message could have issues. Also, it's important to keep in mind that the To: field is purely indicative, as the message will only be sent to the recipient specified in the command line above.

Send a file

We can also send a previously prepared message saved within a standard text file. The syntax of the text file is the same we've just seen for the Interactive mode, i.e.:

After we wrote the following text within a   /email/msg.txt file using a text-editor such as nano or vim, we'll be able to send it using the following terminal command:

Using sSMTP with PHP

sSMTP can be also used as a drop-in replacement of sendmail to send mail through PHP using the native PHP  mail()  function: all we need to do is to configure the sendmail_path parameter within our php.ini file in the following way:

And that's it!

Useful links

Here's a couple links that will surely be useful for anyone who would like to further deepen the topic:

That's it for now: I sincerely hope that this guide will help those who want to setup a simple e-mail sending service to their Linux environment!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

3 Comments on “Linux - How to install and configure sSMTP, a simpler alternative to Postfix and Sendmail A brief tutorial explaining how to setup sSMTP, a simple Linux service to send e-mail through your CentOS machine

  1. Pingback: Install Postfix 3 on Linux CentOS - SMTP, SMTPS, STARTTLS
  2. On debian buster :

    matt@TP430:/ $ sudo apt install ssmtp
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package ssmtp is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    ??

    1. Hello there!

      You’ll need EPEL installed and enabled to get ssmtp.

      Just perform the following command:
      yum –enablerepo=extras install epel-release

      .. and then you can use:
      yum install ssmtp

      Updated the post accordingly! If you manage to fix that, please give us a like on FB/Twitter :)

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.