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).

  1. sudo apt install msmtp msmtp-mta
  2. msmtp --configure <email address>
  3. sudo cp /usr/share/doc/msmtp/examples/msmtprc-system.example /etc/msmtprc
  4. Update /etc/msmtprc with the resulting configure entries, but leave account as default
  5. To use gmail, you'll need to enable two factor auth and then create an application key
  6. Add the following to /etc/msmtprc
  7. For security change the permissions on /etc/msmtprc
    • sudo chmod 0640 /etc/msmtprc
    • sudo chgrp msmtp /etc/msmtprc
  8. sudo systemctl restart msmtpd.service

I like to use mutt for a command line mail application, although a quick test can be done with:

sendmail <youremail@address>

Type in the body of your message and then type ctrl-D to finish.

- Keith