Site icon Ryadel

Linux - How to install and configure sSMTP, a simpler alternative to Postfix and Sendmail

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 gmail@gmail.com 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 aruba_email@ilmiosito.it 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!

 

Exit mobile version