I wanted to send an email notification from command line. I launched a program on my desktop machine at my workplace that would require some days to finish. I want to know when it’s finished and I want to get the result too.
The email will be sent via gmail, it’s the easiest solution. Here, Sid explains nicely how to configure ssmtp on a desktop. Here I repeat the steps:
sudo apt-get install ssmtp“.
Edit the file
/etc/ssmtp/ssmtp.conf and add the following content:
email@example.com mailhub=smtp.gmail.com:465 rewriteDomain=gmail.com AuthUser=username AuthPass=password FromLineOverride=YES UseTLS=YES
For this purpose, I created a dedicated Gmail account.
Test if it works: “
ssmtp firstname.lastname@example.org < filename.txt“.
You can also send emails with the command “
mail -s "Subject of the mail" email@example.com < result.txt
In the intro I mentioned that I want to get the result of a slow program. Here is how I did it: the program writes the result in a file called “
result.txt“. When it’s finished, a shell script is called that sends the content of
result.txt to me:
time ./pe_211.d && ./send-mail.sh
send-mail.sh looks like this:
#!/usr/bin/bash mail -s "PE 211" firstname.lastname@example.org < result.txt
- How to send email from the Linux command line (it didn’t work for me out of the box, I had to edit first
ssmtp.conf, as described above)
- smtp-cli — command line SMTP client (a powerful SMTP command line client with a support for advanced features, written in Perl)
- How to send mail from the command line?