I have a lot of servers up and running doing various tasks. They run scripts, and for most of the scripts I want to know if the outcome was good or bad. Especially bad.
The most common and easy way is to send an email for most of the cases, but I don’t want to setup a mailserver such as postfix in order to do it. I prefer to just use a gmail address in order to complete the task easily.
I found an application-utility which does exactly this simple thing. It is written in perl and it is called sendEmail – not to be confused with sendmail. I figured out that because I just install it when I set up a new server, I can’t find any complete instructions and I need to search around every time in order to make it work. Note that you cannot find sendEmail in the usual yum repositories.
So, in order to start, download the sendEmail tar archive:
Then extract it:
tar -zxvf sendEmail-v1.56.tar.gz
Then copy the sendEmail script to /usr/local/bin. Note that you must have root rights for the operation.
sudo cp -a sendEmail-v1.XX/sendEmail /usr/local/bin
The script needs to be executable, so go make it.
sudo chmod +x /usr/local/bin/sendEmail
Then, go ahead and run:
If everything went fine, the command should produce a usage summary of sendEmail.
So far, so good. But in order to send email via gmail you also need additional libraries which are needed for authentication. The ones missing from me were “Net::SSLeay” and “IO::Socket::SSL”.
As you may have already guessed, these libraries are perl libraries. So in order to install them, run the following commands:
sudo yum install 'perl(Net::SSLeay)'
sudo yum install 'perl(IO::Socket::SSL)'
After this, you should be good to go. In order to send an email via Gmail, the command should look like this:
# send an email sendEmail -v -f $username -s $host -xu $username -xp $password -t $recipient -o tls=yes -u $subject -m $content
This is a line from a bash script that I have written in order to monitor the status of my websites (if they are reachable or non-reachable).
Feel free to use it or contribute to it.