CopyDisable

Tuesday, 4 December 2012

Using external SMTP server for sending mail from Linux shell prompt

We can use ssmtp utility to send emails through some external SMTP service provider from Linux shell or scripts. In this example I am using one Ubuntu Linux box.

Install ssmtp

# apt-get install ssmtp

Edit ssmtp configuration file and add the SMTP information

# pico /etc/ssmtp/ssmtp.conf

#This is SMTP username
AuthUser=pranabs

This is SMTP password
AuthPass=pranabs

#Specifies whether the From header of an email, if any, may override the default domain.
FromLineOverride=YES

#SMTP host
mailhub=smtp.sendgrid.net

#Specifies whether ssmtp does a EHLO/STARTTLS before starting SSL negotiation.
UseSTARTTLS=NO

 

To use mail command we have to install mailutils

# apt-get install mailutils

 

Now testing it from the shell

# echo "This is a test mail" | mail -s "Testing SMTP" pranabs@mkcl.org,pranabksharma@gmail.com

 

Remember we have to disable sendmail (if already present) to use ssmtp.