Easily relay E-Mail through GMail.com on Linux

Today I will show you the easiest way to relay E-Mail from a Linux server through GMail.  There are several reasons why you would want to do this set up.  One is if you server is running at home, because most mail servers that act as realy’s will block your home IP, because home black listed in The Spamhaus Project and other black lists.  GMail is able to allow you sending mail because you are authenicationg with their server before they allow you to relay any mail.  I will also include some helpfull instructions for CentOS users.

So first step is install ssmtp.

If you are running CentOS you will need to add the EPEL repositories, since SSMTP is not currently in the base package repository.

To install EPEL

# rpm -Uvh http://syslogserver.googlecode.com/files/epel-release-5-3.noarch.rpm
# yum -y install ssmtp

Then we want to install SSMTP

#yum install ssmtp
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* Webmin: download.webmin.com
* base: mirror.linux.duke.edu
* epel: mirror.symnds.com
* extras: mirror.metrocast.net
* updates: mirror.metrocast.net
Setting up Install Process
Resolving Dependencies
-> Running transaction check
-> Package ssmtp.i386 0:2.61-15.el5 will be installed
-> Finished Dependency Resolution

Dependencies Resolved

Package                     Arch                       Version                              Repository                  Size
ssmtp                       i386                       2.61-15.el5                          epel                        52 k

Transaction Summary
Install       1 Package(s)

Total download size: 52 k
Installed size: 88 k
Is this ok [y/N]: y
Downloading Packages:
ssmtp-2.61-15.el5.i386.rpm                                                                             |  52 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : ssmtp-2.61-15.el5.i386                                                                                     1/1

ssmtp.i386 0:2.61-15.el5

root@pbx:~ $

Now that SSMTP is install it is time to configure it.

# vi /etc/ssmtp/ssmtp.conf

Modify the AuthUser and AuthPass to match your account information.  The rest of the information can be kept the same.

Now make sure you do not have any other MTA running such as Postfix or Sendmail.

Now move the snedmail binary out of the way and link in the ssmtp binary so that it is used to send mail.

# mv /usr/sbin/sendmail /usr/sbin/no_runsendmail
# ln -s /usr/sbin/ssmtp /usr/sbin/sendmail

Now you can test it with mailx

$ mailx user@domain.com
Subject: Test message
body of test message

Now you should be receving a new E-Mail.