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

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.

Related Posts

  • 40
    What is Sendmail? Sendmail is a mail server used for sending and receiving mails. It works on SMTP (Simple Mail Transfer Protocol ) protocol on port 25. Most of users are familier with sendmail and want to use it also. This article will help that users for installing sendmail server on…
    Tags: mail, sendmail, server
  • 33
    For Send mail Tutorial Click Here Need to be installed sendmail ( yum install sendmail) and mailx (yum install mailx) Create a shell script in linux. vi diskalert.sh #!/bin/sh support="itsupport@xyz.com" # set alert level 90% is default ALERT=90 df -HP | grep -vE '^Filesystem|tmpfs|cdrom' |   while read partition size…
    Tags: install, sendmail, script, mail, shell, send, email

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: