sendEmail configuration

sendEmail is a easy to configure, lightweight SMTP client which can send emails over the console or by scripting (e.g. Bash, Perl), sendEmail is also TLS compatible.

Furthermore a not so difficult opportunity arises to localy encrypt the emails with GnuPG, which will be also demonstrate in this wiki.

Installation

sendEmail can be installed with the Pakfire web interface or via the console:

pakfire install sendEmail

sendEmail command and the options

To send an email over the console, the following command can be used.

/usr/local/bin/sendEmail -f example@mailA.com -t example@mailB.com \
-u "Subject of the mail" -m "Mail message...."\
-s smtp.web.de:25 -xu username -xp top_secret_password

This command includes the most important options.

Options:

  • -f - Surrenders the sender address, if no valid email address exists the receiver address can be used instead.
  • -t - (to) Surrenders the reciver address.
  • -u - (subject) The subject should always be set into quotes.
  • -m - (message) The content of the mail body should also be set in quotes.
  • -s - (server) Delivers the SMTP address and the port of the appropriate reciver.
  • -xu - (username) Indicates the username of the mail account.
  • -xp - (password) Indicates the password of the mail account.

Some further options:

  • -cc - (copy) A second recipient.
  • -bcc - (blind copy) Sends the email to other recipients with hided addresses
  • -o - (advanced option) Includes also TLS activation [-o tls=
  • -a - (attachment) Includes the path to the file attachment.
  • -v[vv] - (verbose) Activates sendEmails logging, the more "v"s the more output. The logging output can be overviewed in/var/log/messages.

sendEmail provides more options and possibilities. A few will follow now.

sendEmail example script

The script was applied exemplarily in /mnt/harddisk/scripts/directory (please adapt it to your own needs). Furthermore a system status script was integrated, which the sendEmail script executes and save the output as a txt file and send it then as an email attachment. The example system state script can be found in here.

After the creation fo the script file,

touch /mnt/harddisk/scripts/my-sendemail.sh

it needs to be made ​​executable,

chmod +x my-sendemail.sh

and was filled with the following content:

#!/bin/bash

####
# my-sendemail.sh execute and send email
####

cd /mnt/harddisk/scripts/;
./my-sysstat.sh > /tmp/stats.txt;

/usr/local/bin/sendEmail -f example@mailA.com -t example@mailB.com \
  -u "System state of IPFire" -m "Good morning, here again, the system state as an attachment" \
  -s smtp.mail.com:25 -xu username -xp top_secret \
  -a /tmp/stats.txt;
rm -rf /tmp/stats.*;

sendEmail TLS-Extension

If you want to use the TLS extension the following option must be specified:

-o tls=yes

Example with TCP-Port 587 for SMTPS:

...
...
/usr/local/bin/sendEmail -f example@mailA.com -t example@mailB.com \
  -u "System state IPFire" \
  -m "Good morning, here again, the system state as an attachment" \
  -s smtp.mail.com:587 \
  -xu username -xp top_secret \
  -o tls=yes \
  -a /tmp/stats.txt;
...

sendEmail verbose-mode

It can be helpful to activate the debug mode of sendEmail so possible problems or errors can be seen. If everything works properly, the verbose option should be removed:

-vv

The return values of a successful TLS connection can look like this:

Mar 29 06:40:15 ipfire sendEmail[742]: DEBUG => Connecting to smtp.web.de:587
Mar 29 06:40:16 ipfire sendEmail[742]: DEBUG => My IP address is: 192.168.22.2
Mar 29 06:40:16 ipfire sendEmail[742]: DEBUG => evalSMTPresponse() - Found SMTP success code: 220
Mar 29 06:40:16 ipfire sendEmail[742]: SUCCESS => Received:     220 web.de (mrweb004) Nemesis ESMTP Service ready
Mar 29 06:40:16 ipfire sendEmail[742]: INFO => Sending:     EHLO ipfire.local
Mar 29 06:40:16 ipfire sendEmail[742]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
Mar 29 06:40:16 ipfire sendEmail[742]: SUCCESS => Received:     250-web.de Hello ipfire.local [178.6.xxx.xxx], 250-SIZE 69920427, 250-AUTH LOGIN PLAIN, 250 STARTTLS
Mar 29 06:40:16 ipfire sendEmail[742]: DEBUG => The remote SMTP server supports TLS :)
Mar 29 06:40:16 ipfire sendEmail[742]: DEBUG => Starting TLS
Mar 29 06:40:16 ipfire sendEmail[742]: INFO => Sending:     STARTTLS
...
...
...

sendEmail with GPG

To sign the status message with your own key the following GPG command line can be used:

/usr/bin/gpg --encrypt -a --recipient ABC123 /tmp/sysinfo.txt;

After encryption, the attachment file extension changed to .asc so the name needs to be adjusted accordingly:

...
-a /tmp/sysinfo.txt.asc;
...

Altogether, it should look like this:

filename = my-sendemail-gpg.sh

#!/bin/bash -

################################################
# sys_info perform encryption and send by email
# ummeegge 25.03.2013
################################################


skript="/mnt/harddisk/mo_scripts/sys_info"

cd $skript;
./sys_info1.sh > /tmp/sysinfo.txt;
/usr/bin/gpg --encrypt -a --recipient A94AB589 /tmp/sysinfo.txt;
/usr/local/bin/sendEmail -f example@mailA.com -t example@mailB.com \
  -u "System Status IPFire" \
  -m "Good morning, here again, the system status as an attachment" \
  -xu username -xp top_secret \
  -s smtp.mail.com:587 \
  -o tls=yes \
  -a /tmp/stats.txt.asc;
rm -rf /tmp/sysinfo.*;

Sendmail with 7zip

If you would like to use password-protected and compressed files (zip/rar or 7z) you can use the 7z addon and install it via Pakfire.
Then sendmail.sh can be extended as follows.

filename = my-sendemail-7z.sh

#!/bin/bash

  ####
  # my-sendemail.sh ausführen und email senden
  ####

  cd /mnt/harddisk/scripts/;
  ./my-sysstat.sh > /tmp/stats.txt;
  sleep 5;
  /usr/local/bin/7z a /tmp/stats.7z /tmp/stats.txt -pHERE-your-Cryptics-password
  sleep 2;
  /usr/local/bin/sendEmail -f example@gmx.com -t example@web.com \
       -u "System Status IPFire" \
       -m "Good morning, here again, the system status as an attachment" \
       -s smtp.web.com:587 \
       -xu username -xp top_secret \
       -a /tmp/stats.7z;
    rm -rf /tmp/stats.*;

sendEmail with log

do you want create a log file before you run the my-sendmail.sh, change the script.

filename = my-sendemail-log.sh

#!/bin/bash

####
# run my-sendemail.sh and send email
####

date=`date`;
logfile="/var/log/sendmail.log";
cd /mnt/harddisk/scripts/;
echo $date > $logfile;
./my-sysstat.sh > /tmp/stats.txt;
sleep 5;
/usr/local/bin/7z a /tmp/stats.7z /tmp/stats.txt -pHIER-dein-cryptisches-PW >> $logfile;
sleep 2;
/usr/local/bin/sendEmail -f beispiel@gmx.de -t beispiel@web.de \
   -u "System Status IPFire" \
   -m "Good morning, here again, the system status as an attachment" \
   -s smtp.web.de:25 \
   -vvv \
   -xu username -xp streng_geheim  \
   -a /tmp/stats.7z >> $logfile;
rm -rf /tmp/stats.*;

sendEmail with variable message text

You can create a message text outside the sendEmail command in a file. also, you can set the message subject in a variable.

filename = my-sendemail-mfile.sh

#!/bin/bash

####
# my-sendemail.sh ausführen und email senden
####

date=`date`;
logfile="/var/log/sendmail.log";
subject="IPFire Status - "$date;
cd /mnt/harddisk/scripts/;
echo $date > $logfile;
./my-sysstat.sh > /tmp/stats.txt;
sleep 5;
/usr/local/bin/7z a /tmp/stats.7z /tmp/stats.txt -pHIER-dein-cryptisches-PW >> $logfile;
sleep 2;
/usr/local/bin/sendEmail -f beispiel@gmx.de -t beispiel@web.de \
   -u "$subject" \
   -o message-file=email.txt \
   -s smtp.web.de:25 \
   -vvv \
   -xu username -xp streng_geheim  \
   -a /tmp/stats.7z >> $logfile;
rm -rf /tmp/stats.*;

Now you must create the message file in the directory /mnt/harddisk/scripts/.

filename = email.txt

hello you,

i send you the message file from yesterday.

best regards

I

Additional informations

The current pakfire sendEmail release is version 1.56 and was released by the Caspian project team on 29 September 2009

Edit Page ‐ Yes, you can edit!

Older Revisions • August 26 at 8:38 pm • Jon