I wrote this post to continue with the sysadmining series asked by Ardian.
Sometimes I need cron scripts to email me the result of something and configuring sendmail or postfix to do that seems a little like killing a mosquito with a bazooka (it works, but it’s not very efficient).
So, what I do is use msmtp.
msmtp is very easy to use and configure. Just write a config file for it (.msmtprc in your $HOME) and make it point to the GMail smtp server.
Something like this works:
Then you $ chmod 600 ~/.msmtprc
And that’s pretty much it. Then to send an email what you do is pipe the mail to msmtp with the address of the person you want to email.
Something like this:
echo -e "Subject:test\nTo:email@example.com\nhello world" | msmtp firstname.lastname@example.org
That command would send an email to email@example.com with the subject “test” and the body “hello world”
The “Subject” and “To” fields are optional, but it’s nice to include them. The \n are new lines.
You can also make a text file and cat it and redirect the output with pipes.
More information for the email could be included, like the text encoding used, etc, but for the stuff I need to email, a subject and a body is usually more than enough.