A command utility that runs your job and sends email to you when it's done.
-
Install ssmtp to send email:
sudo apt-get install ssmtp
-
Configure ssmtp at
/etc/ssmtp/ssmtp.conf
:root=username@gmail.com mailhub=smtp.gmail.com:465 rewriteDomain=gmail.com AuthUser=username AuthPass=password FromLineOverride=YES UseTLS=YES
For other email service like qq or 163, the comfiguration is similar.
-
Clone this reposity and cd in:
git clone https://github.com/EastonWang/mail-exec.git cd mail_exec
-
Install
mail-exec
:sudo install -m 755 mail-exec /usr/bin/mail-exec
-
Configure
mail-exec.rc
file, otherwisemail-exec
will ask you about send_from email and send_to email every time you execute it.copy mail-exec.rc.example ~/.mail-exec.rc
or
copy mail-exec.rc.example etc/mail-exec.rc
Note: Change the the settings in
.rc
file. The send_from email address must be same as your authorization email address configured at/etc/ssmtp/ssmtp.conf
-
Now you can execute your command with mail-exec as prefix:
mail-exec python3 test.py
-
You can also run your command on backgroud with nohub :
nohub mail-exec python3 test.py > nohub.out &
-
You will receive a success email if your program is done successfully:
- Of course, you will get a fail email with error message like this if your program fails: