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

This is SMTP password

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

#SMTP host

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


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",


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