Use Gmail account to send mail from a Shell prompt
Sometimes we want our desktops/servers to send mails automatically, but we dont want to setup a full mail server. sSMTP (not usual SMTP) can be perfect for this. It is extremely simple and resource conserving. In this article we will configure sSMTP and then use it to send outgoing email through gmail account.
Install sSMTP by running the following command in your terminal
[chia]$ sudo apt-get install ssmtp (Ubuntu users)
[chia]$ yum install ssmtp (Fedora users)
Configuring sSMTP is very easy, open /etc/ssmpt/ssmpt.conf is a text editor
[chia]$ vi /etc/ssmpt/ssmlt.conf
Update the following Settings:
root=emailaddress@gmail.com
AuthUser=Gmail-Username
AuthPass=Gmail-Password
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
FromLineOverride=YES
Other mail service can also be configured by changing mailhub to their SMTP server.
Stop Sendmail and replace it with sSMTP.
[chia]$ sudo service sendmail stop
[chia]$ sudo chkconfig --levels 2345 sendmail off
To completely replace Sendmail with sSMTP, copy sendmail to another file and then create a symbolic link from sSMTP to sendmail.
[chia]$ mv /usr/sbin/sendmail /root/.sendmail.backup
[chia]$ sudo ln -s /usr/local/ssmpt/sbin/ssmpt /usr/sbin/sendmail
Once you are done configuring these settings you can try sending a mail.
Open a terminal and run the command
[chia]$ ssmpt reciever-email@example.com
Follow the following format
To: reciever-email@example.com
From: your-email-address@gmail.com
Subject: Test mail
This is a test mail.
There is a blank line between the subject and the body of the mail. After you are done with this you can send the mail by pressing Ctrl-D.
Further you can set a cron job and schedule a mail. Store the mail is some text file. Add this command to your cron.
ssmtp myemailaddress@gmail.com < message.txt
You can also use mail or mailx command to send email.
[chia]$ echo "This is a test mail" | mail -s "Test mail" reciever-email@example.com



























1 Comment
Post new comment