Documentation Center

  • Trials
  • Product Updates

Contents

Configure Raspberry Pi Hardware to Mail IP Address Changes

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 Desktop Using Computer Peripherals.

The Raspbian Wheezy 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:

  1. Open a command line session, as described in Open a Command-Line Session with Raspberry Pi Hardware.

  2. Use a simple editor called nano to edit ssmtp.conf. Enter:

    sudo nano /etc/ssmtp/ssmtp.conf
  3. Modify the AuthUser and AuthPass entries in ssmtp.conf with your Gmail account user name and the password.

  4. Save the changes and exit nano:

    1. Press Ctrl+X.

    2. Enter Y to save the modified buffer.

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

  5. Edit the mailip file in nano by entering:

    sudo nano /etc/network/if-up.d/mailip
  6. Update the RECIPIENTADDR entry in mailip with your email address.

  7. Save the changes and exit nano:

    1. Press Ctrl+X.

    2. Enter Y to save the modified buffer.

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

  8. 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
  9. 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.

Was this topic helpful?