Shell script to send mail via smtp : Send mail from external smtp server

Rate this post

You can use gmail or any other SMTP server as a smart host to send all messages from your Linux / UNIX desktop systems. You need to use a simple program called ssmtp. It accepts a mail stream on standard input with recipients specified on the command line and synchronously forwards the message to the mail transfer agent of a mailhub for the mailhub MTA to process.
Install ssmtp

# yum install ssmtp

Configure smarthost

# vi /etc/ssmtp/ssmtp.conf

Modify the following setting to setup SMTP mail server. Here, we have configured Google SMTP server to send mail.

AuthUser=replytosatya@gmail.com
AuthPass=***********
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

Note: Before using this method to send mail, you need to disable sendmail.

# service sendmail stop

# chkconfig sendmail off

Now, you can use mail / mailx command to send email messages. You can also write a shell script to backup your files and email to somewhere else (see below). You can test settings using following syntax:

echo “This is a test” | mail -s “Test” satya@eduguru.in

Limittation of sSmtp:

sSMTP works well for desktop systems, but it is not a replacement for Sendmail / Postfix / Exim / Qmail for email server environment. This software is perfect for a single user system.

For any query or issue, feel free to discuss on http://discuss.eduguru.in

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

One thought on “Shell script to send mail via smtp : Send mail from external smtp server

  • April 19, 2015 at 1:59 pm
    Permalink

    Once you learn the skill of trimming pubic hair, you can wield your
    razor to create your own style free hand. Keep your blog updated all the
    time with beneficial information and you’ll have your own set of devoted followers in no time.
    Even though you are unseen by the person you are having a
    conversation with, try wearing a smile when you pick up that phone.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: