If the IP address of the Raspberry Pi™ hardware changes,
the board can send you an email notification of the new IP address.
To enable this feature, add your email address to the ssmtp.conf
file
on the hardware.
Before performing this process, connect to the Linux® desktop on the Raspberry Pi hardware using a monitor, keyboard, and mouse, as described in Access the Linux on Raspberry Pi Using Computer Peripherals.
The Raspbian Linux image is configured to include the ssmtp package,
which enables you to send email from the Raspberry Pi hardware. The ssmtp package is a simple mail transfer agent (MTA) that
requires an authenticated email server. For simplicity, ssmtp.conf is configured to use
a Gmail™ server. The configuration file for the ssmtp is located in
/etc/ssmtp/ssmtp.conf
file on the Raspberry Pi hardware:
# # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=postmaster # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=smtp.gmail.com:587 # Where will the mail seem to come from? rewriteDomain=gmail.com # The full hostname hostname=gmail.com # Are users allowed to set their own From: address? # YES - Allow the user to specify their own From: address # NO - Use the system generated From: address FromLineOverride=YES AuthUser=pi AuthPass=raspberry UseSTARTTLS=YES
To update the ssmtp.conf
file:
Open a command line session, as described in Open a Command-Line Session with Raspberry Pi Hardware.
Use a simple editor called nano
to
edit ssmtp.conf
. Enter:
sudo nano /etc/ssmtp/ssmtp.conf
Modify the AuthUser
and AuthPass
entries
in ssmtp.conf
with your Gmail account user
name and the password.
Save the changes and exit nano
:
Press Ctrl+X.
Enter Y to save the modified buffer.
Respond to File Name to Write: /etc/ssmtp/ssmtp.conf
by
pressing Enter.
The nano
editor displays Wrote #
lines
and returns control to the command line.
Edit the mailip
file in nano
by
entering:
sudo nano /etc/network/if-up.d/mailip
Update the RECIPIENTADDR
entry
in mailip
with your email address.
Save the changes and exit nano
:
Press Ctrl+X.
Enter Y to save the modified buffer.
Respond to File Name to Write: /etc/network/if-up.d/mailip
by
pressing Enter.
The nano
editor displays Wrote #
lines
and returns control to the command line.
Enable the auto-email feature by entering the following command on a Linux shell on your Raspberry Pi hardware:
sudo chmod ugo+x /etc/network/if-up.d/mailip
Test the auto-email feature by entering the following on a Linux shell on your Raspberry Pi hardware:
sudo /etc/network/if-up.d/mailip
If the test is successful, auto-email sends you a message with
the IP address of the Raspberry Pi hardware on the subject line.
The message body includes the same network information one gets from
using ifconfig
.
To use a mail server other than the Gmail server, update
the mailhub
, rewriteDomain
, hostname
,
and UseSTARTTLS
entries in ssmtp.conf
.
Specify the values required by the new email server.