Send an email from your Raspberry Pi
If you have a Raspberry used as a server, an automation tool or anything else it may be useful to get some news from him regularly. With sSMTP you can easily send email via the SMTP server from an Internet provider (here Google as an example)
- Update distribution
apt-get update && apt-get upgrade -y
- Install sSMTP, mpack (to encode and decode any attachments) and mailutils that contains the command mail to send / check emails.
apt-get install -y ssmtp mailutils mpack
- Configure ssmtp by editing the file /etc/ssmtp/ssmtp.conf. Add the following lines to the end of file
mailhub=smtp.gmail.com:587 [email protected] AuthPass=PASSWORD useSTARTTLS=YES useTLS=YES
- You may need to create a specific password for the application, Gmail password generating an error for the authentication 534 :
Aug 12 09:23:19 squid sSMTP[21051]: Authorization failed (534 5.7.9 https://support.google.com/accounts/answer/185833 i1sm6469057wjq.42 - gsmtp)
In this case, visit this page https://support.google.com/accounts/answer/185833 and following the instructions you will have a password 16 characters that will replace your current password in the configuration file /etc/ssmtp/ssmtp.conf
- Now test your configuration :
echo "Hello" | mail-s "This is the subject line" [email protected]
- You can redirect the emails generated by the system to an external email address through the file /etc/aliases. For example, by adding the following lines in the file
# /etc/aliases www: root root: [email protected]
Mails generated to the user www will be redirected to the user root which will send emails to your Gmail external address.
- Finally last option if you want a name “readable” as the source of your emails, consider using the chfn command to change the name that will be displayed :
chfn -f "My display name" root
You can now simply and quickly send emails through Gmail SMTP
Pingback: Send an email from your Raspberry Pi | Samuel Le Tonqueze()