Recital

Login Register

HOWTO: Use a Gmail Account To Relay Email From a Shell Prompt on Redhat/Centos/Fedora

Usually, you do not need to setup an email server under Linux. Most GUI email clients support Gmail POP3 and IMAP configurations. But, how do you send mail via the standard /usr/bin/mail user agents in a shell script? Programs such as sendmail / postfix / exim can be configured as a gmail smarthost but they are largely overkill for this use. The ssmtp program is a neat utility that does just that for you via gmail.

 

Step 1 - Reference the fedora repo as centos does not include ssmtp

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

Step 2 - Install ssmtp

# yum install ssmtp

Step 3 - Configure ssmtp to use gmail to send email

# vi /etc/ssmtp/ssmtp.conf

Then insert the following text:

#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# See the ssmtp.conf(5) man page for a more verbose explanation of the
# available options.
#
root=This email address is being protected from spambots. You need JavaScript enabled to view it.
mailhub=smtp.gmail.com:465
AuthUser=This email address is being protected from spambots. You need JavaScript enabled to view it.
AuthPass=yourpassword
RewriteDomain=yourdomain.com
FromLineOverride=YES
UseTLS=YES

Step 4 - Rename sendmail

# service sendmail stop
# chkconfig sendmail off
# mv /usr/sbin/sendmail /root
# ln -s /usr/sbin/ssmtp /usr/sbin/sendmail

That's it. Now test it.

# echo "This is the message body" | mail -s "This is the message subject" This email address is being protected from spambots. You need JavaScript enabled to view it.

Very useful indeed!

Twitter

Copyright © 2024 Recital Software Inc.

Login

Register

User Registration
or Cancel