I have a few Raspberry Pi's on my network and it can get tedious to SSH into each one to do various activities such as upgrades or security scans. There are lots of software tools that send emails and setting up the full fledged mail systems such as postfix or sendmail can be daunting. msmtp is a minimal smtp client that enables you to forward mail to an external mail system for delivery. I set this up with my mail provider, gmail, in a few short steps.
I run Debian Linux systems, so these instructions will work verbatim on those systems. There's nothing fancy about the setup so it will work on other distros that have the msmtp packages (or need minor adjustment).
- sudo apt install msmtp msmtp-mta
- msmtp --configure <email address>
- sudo cp /usr/share/doc/msmtp/examples/msmtprc-system.example /etc/msmtprc
- Update /etc/msmtprc with the resulting configure entries, but leave account as default
- To use gmail, you'll need to enable two factor auth and then create an application key
- Add the following to /etc/msmtprc
- auth on
- user <your@emailaddress>
- password <your application key>
- For security change the permissions on /etc/msmtprc
- sudo chmod 0640 /etc/msmtprc
- sudo chgrp msmtp /etc/msmtprc
- sudo systemctl restart msmtpd.service
I like to use mutt for a command line mail application, although a quick test can be done with:
Type in the body of your message and then type ctrl-D to finish.