SSMTP is a tiny simple utility which lets you relay your Linux system’s emails to Google Or Microsoft Office 365 accounts. Its pretty simple and straightforward utility which forwards your Linux system’s emails to reliable relay mail servers like Google or MSN and then email is forwarded to the destination addresses using those SMTP servers (smtp.gmail.com or smtp.office365.com). One main point to understand here is that its not a full fledged mail server, its just a utility which forwards automated emails to an external email address. In this article, we will learn how to install and configure SSMTP to use Gmail and Office365 email accounts for email sending.
How SSMTP Works
Before we go ahead with its installation and configuration process, lets understand how it works. Once it has been installed and configured on any Linux system, all emails from root, nobody or any other such applications will be forwarded to SSMTP. We can also configure our PHP, Python, Ruby applications to forward their emails to this utility, SSMTP uses the concept of Mailhub. Mailhub could be either Gmail SMTP server or Microsof Office365 SMTP server. As soon as it gets email , it forwards this email to the configured Mailhub and the email is delivered to the destination address using your specified Google/Office365 address.
Installing SSMTP on CentOS and Ubuntu
The installation process for this utility is pretty simple, use following command to install it on RHEL based systems (RHEL, CentOS, Fedora).
For Ubuntu and Debian, use following command to install it.
As soon as the installation is complete, you should be able to see a directory “/etc/ssmtp” on your system. All configuration files will be located in this directory. Let’s go ahead and configure SSMTP to use Gmail and Office365 address.
Configuring Linux System to use SSMTP instead of Sendmail / Postfix
By default, Linux system uses Sendmail or Postfix (depending on which one is installed) to relay emails to the outside world. But once we have installed SSMTP and want to use it for external relay, we need to configure our Linu system to use SSMTP by default. First of all make sure to stop sendmail or postfix services.
If you are using CentOS 6 or previous, use following commands.
Now disable the start of sendmail or postfix on system boot.
We will be using Linux’s “alternatives” utility to configure SSMTP as default email utility, run following command to set it as default:
It should prompt you to set the SSMTP as default here by specifying its number in the list.
Configuring SSMTP to use Office365 and Gmail Address
Let’s edit “/etc/ssmtp/ssmtp.conf” file using any text editer application (Vi, Vim, Pico, Nano) , and specify the value for following parameters . If anyone of the followings is not already there in file, simply add it.
Here are the values which should be specified for the above mentioned parameters.
- root : It should be the email account which will be receiving the emails.
- mailhub: Value of this parameter for Office365 account should be “smtp.office365.com:587” and for Gmail account, you can use “smtp.gmail.com:587” .
- AuthUser and AuthPass : should be your actual email address and password for Gmail or Office365 account.
- UseSTARTTLS : should be “Yes”.
- TLS_CA_File: should be the path to your certificate file, typically ; /etc/pki/tls/certs/ca-bundle.crt .
- RewriteDomain: should be your current domain name which is configured on server, if no domain name configured, use “localhost” here.
- Hostname : should be “localhost” or your actual host-name for Linux system.
- FromLineOverride: should be “Yes”.
Following screenshot should clarify the above instructions further.
That’s it, save the configuration file and you are good to go. Unlike Sendmail or Postfix, it does not need any running daemon, you can code your application to use this utility to send out emails to reliable SMTP services like Gmail or Microsoft.
Verifying SSMTP Email Activity
Once SSMTP has been configured, we need to verify that email is actually getting forwarded to the external mailhub. For this purpose, simply run following command on the terminal, replace the destination address with the address of your choice.
It should deliver fine to your mention address, you can view /var/log/maillog file if email delivery is unsuccessful.
This is a very useful utility, but it comes with many limitations. You can not use it as a complete mail server. It does not offer anything for receiving emails. It is just a tool to send out emails to external mail servers. It is useful in many situations, specially when you want to avoid your system IP getting blacklisted due to email volume, or you don’t want to rely on your system for email deliver, rather want to use Gmail or Microsoft addresses/email servers for stable email delivery.