Monday, June 18, 2012

How to send email alert without using sendmail or postfix

Hi All,

Recently I came across a problem where I had to send email alert(with out any attachment) about system health. One way was to configure Sendmail or Postfix. But It was overkill. I had to just send an alert and forget. For that tiny utility ssmtp comes in a very  handy way. First just install ssmtp using rpm of deb package. Thet configure /etc/ssmtp/ssmtp.conf file

  root=user@example.com

  AuthUser=username
  AuthPass=password
  AuthMethod=CRAM-MD5

  mailhub=mail.example.com  //your smtp server

  rewriteDomain=example.com  //your domain name

  hostname=hostname.domain //your machine hostname 
 
 
and bingo you are ready to use ssmtp to send mail
just try following command

echo "Hello world"| ssmtp yourmailid@example.com
 
also you can add these line in cronjob also. 
 

Note:-
1. Make ssmtp.conf permission as 640 aka chmod 640 /etc/ssmtp/ssmtp.conf
2. Make sure ssmtp user has no valid shell. Techincally it should have /sbin/nologin as shell
 
 
 Source:- 
ssmtp guide





No comments:

Post a Comment