ConfigureRaspberry PiHardware to Mail IP Address Changes
如果Raspberry PI™硬件的IP地址发生变化,则可以向您发送新IP地址的电子邮件通知。要启用此功能,请将您的电子邮件地址添加到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使用计算机外围设备访问覆盆子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
文件:
Open a command line session, as described inOpen Command-Line Session with Raspberry Pi Hardware。
Use a simple editor called
nano
to editssmtp.conf
。进入:sudo nano /etc/ssmtp/ssmtp.conf
Modify the
AuthUser
和AuthPass
entries inssmtp.conf
with your Gmail account user name and the password.Save the changes and exit
nano
:PressCtrl+X。
EnterYto save the modified buffer.
Respond to
File Name to Write: /etc/ssmtp/ssmtp.conf
by pressingEnter。The
nano
editor displaysWrote # lines
和returns control to the command line.
Edit the
mailip
file innano
by entering:sudo nano /etc/network/if-up.d/mailip.
Update the
RECIPIENTADDR
entry inmailip
使用您的电子邮件地址。Save the changes and exit
nano
:PressCtrl+X。
EnterYto save the modified buffer.
Respond to
File Name to Write: /etc/network/if-up.d/mailip
by pressingEnter。The
nano
editor displaysWrote # lines
和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
。
要使用除Gmail服务器以外的邮件服务器,请更新mailhub
,rewriteDomain
,hostname
, andUseSTARTTLS
entries inssmtp.conf
。Specify the values required by the new email server.