{"id":1357,"date":"2020-11-26T09:52:38","date_gmt":"2020-11-26T01:52:38","guid":{"rendered":"http:\/\/blog.zengqq.com.cn\/?p=1357"},"modified":"2020-11-26T09:57:40","modified_gmt":"2020-11-26T01:57:40","slug":"%e6%a0%91%e8%8e%93%e6%b4%be%e5%88%86%e5%8f%91%e8%87%aa%e5%b7%b1%e7%9a%84%e5%85%ac%e7%bd%91ip","status":"publish","type":"post","link":"https:\/\/blog.zengqq.com.cn\/?p=1357","title":{"rendered":"\u6811\u8393\u6d3e\u90ae\u4ef6\u5206\u53d1\u529f\u80fd\u8bbe\u7f6e"},"content":{"rendered":"\n<p>If the IP address of the Raspberry Pi\u2122 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&nbsp;<code>ssmtp.conf<\/code>&nbsp;file on the hardware.<\/p>\n\n\n\n<p>Before performing this process, connect to the Linux<sup>\u00ae<\/sup>desktop on the Raspberry Pi hardware using a monitor, keyboard, and mouse, as described in&nbsp;<a href=\"https:\/\/www.mathworks.com\/help\/supportpkg\/raspberrypi\/ug\/set-up-raspberry_pi-hardware-as-a-linux-desktop-or-terminal.html\">Access the Linux on Raspberry Pi Using Computer Peripherals<\/a>.&nbsp;<\/p>\n\n\n\n<p>The Raspbian Linux image is configured to include the&nbsp;<em>ssmtp<\/em>&nbsp;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\u2122 server. The configuration file for the ssmtp is located in<code>\/etc\/ssmtp\/ssmtp.conf<\/code>&nbsp;file on the Raspberry Pi hardware:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\n# Config file for sSMTP sendmail\n#\n# The person who gets all mail for userids &lt; 1000\n# Make this empty to disable rewriting.\nroot=postmaster\n \n# The place where the mail goes. The actual machine name is required no\n# MX records are consulted. Commonly mailhosts are named mail.domain.com\nmailhub=smtp.gmail.com:587\n \n# Where will the mail seem to come from?\nrewriteDomain=gmail.com\n \n# The full hostname\nhostname=gmail.com\n \n# Are users allowed to set their own From: address?\n# YES - Allow the user to specify their own From: address\n# NO - Use the system generated From: address\nFromLineOverride=YES\n \nAuthUser=pi\n \nAuthPass=raspberry\n \nUseSTARTTLS=YES<\/pre>\n\n\n\n<p>To update the&nbsp;<code>ssmtp.conf<\/code>&nbsp;file:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Open a command line session, as described in&nbsp;<a href=\"https:\/\/www.mathworks.com\/help\/supportpkg\/raspberrypi\/ug\/opening-a-serial-command-line-session-with-your-raspberry_pi-hardware.html\">Open a Command-Line Session with Raspberry Pi Hardware<\/a>.<\/li><li>Use a simple editor called&nbsp;<code>nano<\/code>&nbsp;to edit&nbsp;<code>ssmtp.conf<\/code>. Enter:sudo nano \/etc\/ssmtp\/ssmtp.conf<\/li><li>Modify the&nbsp;<code>AuthUser<\/code>&nbsp;and&nbsp;<code>AuthPass<\/code>&nbsp;entries in&nbsp;<code>ssmtp.conf<\/code>&nbsp;with your Gmail account user name and the password.<\/li><li>Save the changes and exit&nbsp;<code>nano<\/code>:<ol><li>Press&nbsp;<strong>Ctrl+X<\/strong>.<\/li><li>Enter&nbsp;<strong>Y<\/strong>&nbsp;to save the modified buffer.<\/li><li>Respond to&nbsp;<code>File Name to Write: \/etc\/ssmtp\/ssmtp.conf<\/code>&nbsp;by pressing&nbsp;<strong>Enter<\/strong>.&nbsp;The&nbsp;<code>nano<\/code>&nbsp;editor displays&nbsp;<code>Wrote # lines<\/code>and returns control to the command line.<\/li><\/ol><\/li><li>Edit the&nbsp;<code>mailip<\/code>&nbsp;file in&nbsp;<code>nano<\/code>&nbsp;by entering:sudo nano \/etc\/network\/if-up.d\/mailip<\/li><li>Update the&nbsp;<code>RECIPIENTADDR<\/code>&nbsp;entry in&nbsp;<code>mailip<\/code>with your email address.<\/li><li>Save the changes and exit&nbsp;<code>nano<\/code>:<ol><li>Press&nbsp;<strong>Ctrl+X<\/strong>.<\/li><li>Enter&nbsp;<strong>Y<\/strong>&nbsp;to save the modified buffer.<\/li><li>Respond to&nbsp;<code>File Name to Write: \/etc\/network\/if-up.d\/mailip<\/code>&nbsp;by pressing&nbsp;<strong>Enter<\/strong>.&nbsp;The&nbsp;<code>nano<\/code>&nbsp;editor displays&nbsp;<code>Wrote # lines<\/code>and returns control to the command line.<\/li><\/ol><\/li><li>Enable the auto-email feature by entering the following command on a Linux shell on your Raspberry Pi hardware:&nbsp;sudo chmod ugo+x \/etc\/network\/if-up.d\/mailip<\/li><li>Test the auto-email feature by entering the following on a Linux shell on your Raspberry Pi hardware:&nbsp;sudo \/etc\/network\/if-up.d\/mailipIf 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&nbsp;<code>ifconfig<\/code>.<\/li><\/ol>\n\n\n\n<p>To use a mail server other than the Gmail server, update the&nbsp;<code>mailhub<\/code>,&nbsp;<code>rewriteDomain<\/code>,&nbsp;<code>hostname<\/code>, and&nbsp;<code>UseSTARTTLS<\/code>&nbsp;entries in&nbsp;<code>ssmtp.conf<\/code>. Specify the values required by the new email server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If the IP address of the  [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[],"class_list":["post-1357","post","type-post","status-publish","format-standard","hentry","category-live"],"_links":{"self":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1357"}],"version-history":[{"count":3,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1357\/revisions"}],"predecessor-version":[{"id":1360,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1357\/revisions\/1360"}],"wp:attachment":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}