Send email from command line using gmail and ssmtp

This is a very good tool i use to email me of any notifications on my centos box. Plus i use it to send emails when i am working on command line.

If you havent already installed the EPEL i386 Repo, then do
# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

then,
# yum remove sendmail (optional)
# yum install ssmtp

Now, configure the ssmtp.conf file:
# vi /etc/ssmtp/ssmtp.conf
AuthUser=(username)@gmail.com
AuthPass=(your – password)
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

# service sendmail stop ( if not removed above)
# chkconfig sendmail off (if not removed above)
# mkdir /root/.backup
# mv /usr/sbin/sendmail /root/.backup/
# whereis ssmtp
ssmtp: /usr/sbin/ssmtp /etc/ssmtp /usr/share/man/man8/ssmtp.8.gz
# ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
# echo “This is a test email” | mail -s “Test” merocentos@gmail.com
This will send an email to merocentos@gmail.com …..
You can use this on a script,cron and any log messages now to make the centos box email you the issues…. comment on any help needed.

Advertisements