How To Setup sSMTP on CentOS 5.9

In this how to, I assume you already have a running CentOS 5.9 server. I am going to share how to install and setup sSMTP 2.61 on CentOS 5.9 version. This how to has been tested with Mutt 1.4.2.2i as a mail client. I am using Mutt here because I want to have a customize From display instead of displaying root.

First, we must ensure everything are up to date by running the following commands: –

# yum check-update
# yum -y update

Then, lets download the EPEL repository for CentOS 5.9 x86_64 architecture: –

# wget -c http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

Next, install the EPEL repository: –

# rpm -ivh epel-release-5-4.noarch.rpm

Now, install sSMTP

# yum -y install ssmtp

If you have Sendmail installed, you need to run the following command below to change your default Mail Transfer Agent (MTA): –

# alternatives --config mta

There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.ssmtp

Enter to keep the current selection[+], or type selection number: 2

You can verify the sendmail binaries by running the command below: –

# sendmail -V
sSMTP 2.61 (Not sendmail at all)

Now, sSMTP is installed and we will configure the mail server info to relay outgoing email. We going to create new configuration files as below: –

# mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.orig
# touch /etc/ssmtp/ssmtp.conf
# mv /etc/ssmtp/revaliases /etc/ssmtp/revaliases.orig
# touch /etc/ssmtp/revaliases

Next, we will configure sSMTP to forward email to any shared hosting server either running CPanel or DirectAdmin.

Include the following below in /etc/ssmtp/ssmtp.conf file: –

root=postmaster
mailhub=mail.yourdomain.com:587
Hostname=localhost
FromLineOverride=YES
AuthUser=username@yourdomain.com
AuthPass=YourPassWord
UseSTARTTLS=YES

Include the following below in /etc/ssmtp/revaliases file: –

root:username@yourdomain.com:mail.yourdomain.com:587

Include the following below in /root/.muttrc file: –

set envelope_from=yes
set from="username@yourdomain.com"
set realname="Prefer From Display"

If you an option to forward email to Gmail server, you can configure using steps below.

Replace previous configuration to below in /etc/ssmtp/ssmtp.conf file: –

root=postmaster
mailhub=smtp.gmail.com:587
Hostname=username@gmail.com
FromLineOverride=YES
AuthUser=username@gmail.com
AuthPass=YourPassWord
UseSTARTTLS=YES

Replace previous configuration to below in /etc/ssmtp/revaliases file: –

root:username@gmail.com:smtp.gmail.com:587

Replace previous configuration to below in /root/.muttrc file: –

set envelope_from=yes
set from="username@gmail.com"
set realname="Prefer From Display"

Next, you can start sending email using your preferred email server using command below: –

# echo "Testing outgoing email" | mutt -s "Testing" receipient@receivermail.com

Finally, with all the configuration above I hope you are able to use and enjoy your sSMTP to send an email. Thank you.