Skip to content

Email notification

Q-engineering edited this page Sep 18, 2023 · 7 revisions

output image

We use Gmail as it can forward your emails to any other address.


However, if you want to install this email engine on another RPi, here are the steps.

$ sudo apt-get install msmtp ca-certificates

Less secure apps

Before you can send an email to any address, you must register your app with Google. The Raspberry Pi does not meet all of Google's security requirements. To better protect your Google account from hackers, the Raspberry Pi gets its own unique password. With this password, it can only send emails to Gmail, not open your entire Google account.

First, check if you enabled the 2-Step Verification when you log in to your Google account. Without 2-Step Verification, Google will not generate the needed password.

output image

The next step is to generate the password by giving the Raspberry Pi an appropriate name, here YoloCam. Let the images speak for themselves.

output image
output image
output image
output image
output image
Your password must be entered in the /etc/msmtprc file. By the way, the used gbxcthxuwxppxoxh is just an example.

msmtprc

$ sudo nano /etc/msmtprc
account default
host smtp.gmail.com
port 587
logfile /tmp/msmtp.log
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

auth login
user username@gmail.com
password thepassword
from First Last Name

output image

Close with <Ctrl>+<X>, <Y>, <Enter>.

Now you can test the connection with the next command:

echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --from=default -t johndoe123@his_mail.us

Of course, you have to replace johndoe123@his_mail.us with your own email address.

Clone this wiki locally