I didn’t see a tip/tricks thread, but I wanted to leave a few for posterity and future refernce
This is a simple way to send mails from the command line using a Gmail account. No need to install any mailservers or other bloat.
Why would you want to do this? Well, it’s an easy way to send e-mail notifications from scripts.
For example, I am using the Pi not only for Kodi, but as as a central fileserver. I set-up some scripts and cron-jobs to auto-sync chosen directories and e-mail me upon success or error.
For this purpose I set-up a separate/throwaway Gmail account for my pi.
Mutt is a very capable e-mail client, and is surprisingy pleasant to work with.
OK. Here we go:
sudo apt-get install openssl libsasl2-modules #Required for Gmail authentication
sudo apt-get install mutt
Now edit .muttrc with your account details.
Paste the following into .muttrc , changing the username (3 instances) and password (2 instances).
set from = "email@example.com" set realname = "username" set imap_user = "firstname.lastname@example.org" set imap_pass = "password" set folder = "imaps://imap.gmail.com:993" set spoolfile = "+INBOX" set record="+[Gmail]/Sent Mail" set postponed ="+[Gmail]/Drafts" set header_cache =~/.mutt/cache/headers set message_cachedir =~/.mutt/cache/bodies set certificate_file =~/.mutt/certificates set smtp_url = "smtp://email@example.com:587/" set smtp_pass = "password" set move = no set imap_keepalive = 900 set record="~/.mutt/mails/sent"
Save and close .muttrc
send a test mail:
echo “This is the body text” | mutt -s “This is the subject line” firstname.lastname@example.org
or to use the mutt interface
mutt -s “This is the subject line” email@example.com
Your first attempt should fail with “SASL authentication failed”, but Gmail will mail you to warn that a new device is trying to use your account.
To unblock it. Login to your gmail account in a browser and go to https://www.google.com/settings/security/lesssecureapps