Main Content

ConfigureRaspberry PiHardware to Mail IP Address Changes

如果Raspberry PI™硬件的IP地址发生变化,则可以向您发送新IP地址的电子邮件通知。要启用此功能,请将您的电子邮件地址添加到ssmtp.conffile 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使用计算机外围设备访问覆盆子PI上的Linux

The Raspbian Linux image is configured to include thessmtppackage, 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 thessmtp.conf文件:

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

  2. Use a simple editor callednanoto editssmtp.conf。进入:

    sudo nano /etc/ssmtp/ssmtp.conf
  3. Modify theAuthUserAuthPassentries inssmtp.confwith your Gmail account user name and the password.

  4. Save the changes and exitnano:

    1. PressCtrl+X

    2. EnterYto save the modified buffer.

    3. Respond toFile Name to Write: /etc/ssmtp/ssmtp.confby pressingEnter

      Thenanoeditor displaysWrote # lines和returns control to the command line.

  5. Edit themailipfile innanoby entering:

    sudo nano /etc/network/if-up.d/mailip.
  6. Update theRECIPIENTADDRentry inmailip使用您的电子邮件地址。

  7. Save the changes and exitnano:

    1. PressCtrl+X

    2. EnterYto save the modified buffer.

    3. Respond toFile Name to Write: /etc/network/if-up.d/mailipby pressingEnter

      Thenanoeditor displaysWrote # lines和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 usingifconfig

要使用除Gmail服务器以外的邮件服务器,请更新mailhub,rewriteDomain,hostname, andUseSTARTTLSentries inssmtp.conf。Specify the values required by the new email server.