{"id":1377,"date":"2020-11-27T08:09:56","date_gmt":"2020-11-27T00:09:56","guid":{"rendered":"http:\/\/blog.zengqq.com.cn\/?p=1377"},"modified":"2020-12-24T22:41:17","modified_gmt":"2020-12-24T14:41:17","slug":"%e5%88%a9%e7%94%a8mutt%e5%92%8cmsmtp%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/blog.zengqq.com.cn\/?p=1377","title":{"rendered":"\u5229\u7528Mutt\u548cMsmtp\u53d1\u9001\u90ae\u4ef6"},"content":{"rendered":"\n<p>\u6811\u8393\u6d3e\u4f7f\u7528\u7684wifi\u8054\u7f51\uff0c\u5728\u5bbf\u820d\u4f7f\u7528\u7684\u662f\u516c\u5171\u7f51\u7edc\uff0c\u4e0d\u80fd\u8bbe\u7f6e\u9759\u6001ip\uff0c\u6bcf\u6b21\u6811\u8393\u6d3e\u4e0a\u7535\u5f00\u673a\u540eip\u5730\u5740\u53ef\u80fd\u4f1a\u6539\u53d8\uff0c\u6240\u4ee5\u8ba9\u6811\u8393\u6d3e\u5f00\u673a\u8054\u7f51\u540e\u81ea\u52a8\u53d1\u9001ip\u5730\u5740\u5230QQ\u90ae\u7bb1<\/p>\n\n\n\n<p>\u4e00\u3001\u5b89\u88c5mutt\u548cmsmtp<\/p>\n\n\n\n<p>mutt: \u662f\u4e00\u4e2aLinux\u4e0b\u7684\u90ae\u4ef6\u7a0b\u5e8f\uff0cMutt \u66f4\u50cf\u4e00\u4e2a\u6587\u4ef6\u7ba1\u7406\u5668\uff0c\u53ea\u4e0d\u8fc7\u5b83\u7ba1\u7406\u7684\u662femail\u3002<\/p>\n\n\n\n<p>msmtp: \u662fLinux\u4e0b\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u6613\u7528\u7684smtp\u5ba2\u6237\u7aef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install mutt<br>sudo apt-get install msmtp<\/pre>\n\n\n\n<p>\u4e8c\u3001\u914d\u7f6emutt\u548cmsmtp<\/p>\n\n\n\n<p>1\u3001\u914d\u7f6emsmtp,\u5728\u7528\u6237\u7684\u6839\u76ee\u5f55\u4e0b\u65b0\u5efa\u6587\u4ef6.msmtprc,\u5185\u5bb9\u5982\u4e0b:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">account default<br>host smtp.aliyun.com<br>from \u4f60\u7684\u90ae\u7bb1\u5730\u5740<br>auth plain<br>user \u4f60\u7684\u90ae\u7bb1\u5730\u5740<br>password \u4f60\u7684\u90ae\u7bb1\u5bc6\u7801<br>logfile \/var\/log\/msmtp.log<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>host<\/strong>&nbsp;\u4f60\u7684\u90ae\u7bb1\u7684SMTP\u670d\u52a1\u5668\u5730\u5740,\u53ef\u4ee5\u5728\u90ae\u4ef6\u7684\u7f51\u7ad9\u4e0a\u67e5\u5230,\u6211\u7528\u7684\u963f\u91cc\u4e91\u7684\u90ae\u7bb1,\u6240\u4ee5\u662faliyun.com\u540e\u7f00<\/li><li><strong>from<\/strong>&nbsp;\u8fd9\u91cc\u662f\u53d1\u4ef6\u4eba\u5730\u5740,\u5728\u6536\u4ef6\u65b9\u4f1a\u663e\u793a,\u8bbe\u7f6e\u6210\u4f60\u7ed9\u6811\u8393\u6d3e\u7533\u8bf7\u7684\u90ae\u7bb1\u5730\u5740<\/li><li><strong>user<\/strong>&nbsp;\u8fd9\u91cc\u662f\u7528\u6237\u540d,\u7f51\u4e0a\u6709\u7528\u6237\u8bf4\u8fd9\u91cc\u8bbe\u7f6e\u90ae\u7bb1\u7684\u7528\u6237\u540d\u5373@\u7b26\u53f7\u524d\u9762\u7684\u5b57\u7b26\u4e32\u5c31\u53ef\u4ee5,\u6211\u6ca1\u6709\u5c1d\u8bd5,\u8fd8\u662f\u8bbe\u7f6e\u7684\u6211\u7684\u90ae\u7bb1\u5730\u5740,\u5efa\u8bae\u5148\u4f7f\u7528\u90ae\u7bb1\u5730\u5740,\u914d\u7f6e\u6210\u529f\u4e4b\u540e\u53ef\u4ee5\u81ea\u5df1\u8fdb\u884c\u4fee\u6539<\/li><li><strong>password<\/strong>&nbsp;\u8fd9\u4e2a\u5c31\u662f\u81ea\u5df1\u90ae\u7bb1\u7684\u5bc6\u7801,\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684,\u4f46\u662f\u8fd9\u91cc\u662f\u660e\u6587\u5bc6\u7801,\u8981\u6ce8\u610f\u4fdd\u5bc6:)<\/li><li><strong>logfile<\/strong>&nbsp;\u8fd9\u662fmsmtp\u7684\u7a0b\u5e8f\u8fd0\u884c\u65e5\u5fd7\u6587\u4ef6\u8def\u5f84,\u9700\u8981\u81ea\u5df1\u521b\u5efa,msmtp\u81ea\u5df1\u4e0d\u4f1a\u521b\u5efa.\u5728\u53d1\u9001\u90ae\u4ef6\u4e4b\u540e\u7a0b\u5e8f\u4f1a\u628a\u53d1\u9001\u65e5\u5fd7\u5199\u5230\u8fd9\u4e2a\u8def\u5f84\u7684\u6587\u4ef6\u91cc\u3002<\/li><\/ul>\n\n\n\n<p>2\u3001\u914d\u7f6emutt\u7684\u6587\u4ef6,\u540c\u6837\u5728\u7528\u6237\u6839\u76ee\u5f55\u4e0b\u65b0\u5efa\u6587\u4ef6.muttrc,\u5185\u5bb9\u5982\u4e0b:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">set sendmail=\"\/usr\/bin\/msmtp\"<br>set use_from=yes<br>set realname=\"RaspberryPi\"<br>set editor=\"vim\"<\/pre>\n\n\n\n<p>\u3000\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6d4b\u8bd5\u53d1\u9001\u90ae\u7bb1\u662f\u5426\u6210\u529f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \u201chello world\u201d | mutt -s \u201ctitle\u201d xxx@gmail.com<\/pre>\n\n\n\n<p>\u4e8c\u3001\u8bbe\u7f6e\u6811\u8393\u6d3e\u8bfb\u53d6Ip\u5730\u5740\u5e76\u901a\u8fc7\u90ae\u4ef6\u53d1\u9001<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u811a\u672c\u6587\u4ef6\u53c2\u8003\u7f51\u4e0a\u7684\u6587\u7ae0 send-ip-mail.sh<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br># check network availability<br>while true<br>do<br>TIMEOUT=5<br>SITE_TO_CHECK=\"www.126.com\"<br>RET_CODE=`curl -I -s --connect-timeout $TIMEOUT $SITE_TO_CHECK -w %{http_code} | tail -n1`<br>if [ \"x$RET_CODE\" = \"x200\" ]; then<br>echo \"Network OK, will send mail...\"<br>break<br>else<br>echo \"Network not ready, wait...\"<br>sleep 1s<br>fi<br>done<br># get the IP address of eth0, e.g. \"192.168.16.5\"<br>ETH0_IP_ADDR=`ifconfig eth0 | sed -n \"2,2p\" | awk '{print substr($2,1)}'`<br># send the Email<br>echo \"Current time: `date '+%F %T'`. Enjoy it\" | mutt -s \"IP Address of Raspberry Pi: $ETH0_IP_ADDR\" xxx@gmail.com<\/pre>\n\n\n\n<p>\u4f7f\u7528chmod +x send-ip-mail.sh\u6dfb\u52a0\u6267\u884c\u6743\u9650\u540e\uff0c\u8fd0\u884c\u67e5\u770b\u662f\u5426\u53ef\u4ee5\u53d1\u9001ip\u5730\u5740\u3002<\/p>\n\n\n\n<p>\u5728rc.local\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5f00\u673a\u6267\u884c\u8be5\u811a\u672c\u7684\u547d\u4ee4\u540e\uff0c\u4e0a\u7535\u91cd\u542f\u53d1\u73b0\u4e0d\u80fd\u63a5\u6536\u5230\u90ae\u4ef6\uff0c\u540e\u6765\u4e0a\u7f51\u67e5\u770b\u53d1\u73b0\u662f\u6743\u9650\u95ee\u9898\uff0c\u7ecf\u8fc7\u4e00\u756a\u6298\u817e\uff0c\u540e\u6765\u9009\u62e9\u628a.muttrc\uff0c.msmtprc\u548csend-ip-mail.sh\u6587\u4ef6\u90fd\u590d\u5236\u5230\/boot\u76ee\u5f55\u4e0b\uff0c\u5728rc.local\u4e2d\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff0c\u6700\u540e\u91cd\u65b0\u4e0a\u7535\u53ef\u4ee5\u63a5\u6536\u5230\u6811\u8393\u6d3e\u53d1\u6765\u7684\u90ae\u4ef6\uff0c\u901a\u8fc7\u90ae\u4ef6\u91cc\u7684ip\u5730\u5740ssh\u767b\u5f55\u6b63\u5e38\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/bbsmax.ikafan.com\/static\/L3Byb3h5L2h0dHBzL2ltZzIwMTguY25ibG9ncy5jb20vYmxvZy8xODQzNDQ4LzIwMTkxMC8xODQzNDQ4LTIwMTkxMDI0MjE0MjA4MzQ1LTEwMjIxODcyNDUucG5n.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u56e0\u4e3a\u53ea\u5728\/home\/pi\u4e0b\u8bbe\u7f6e\u4e86pi\u7684msmtp\u6240\u4ee5\uff0c\u53ea\u6709\/home\/pi\u4e0b\u7684\u6587\u4ef6\u624d\u6709\u6743\u9650\u88abmutt\u53d1\u9001<br>\u4e8e\u662f\u65b0\u5efa\/home\/pi\/ip.txt, \u5e76\u4fee\u6539\u4e86.sh\u6587\u4ef6\u7684\u88ab\u6267\u884c\u6587\u4ef6\u6587\/home\/pi\/ip.txt<br>\u8bd5\u4e86\u4e00\u4e0b<br>echo &#8220;$ip2&#8221; | mutt -s &#8220;ip&#8221; siemen.zem@gmail.com &lt;ip.txt<br>gmail\u80fd\u6536\u5230\u6211\u7684ip.txt\u4e86\uff0c<br>\u53c8\u8bd5\u4e86\u4e00\u4e0bsh\u4e00\u4e0b\u6211\u7684.sh<br>vim \/home\/pi\/ip.txt (\u6545\u610f\u5f15\u6765\u6bd4\u5bf9\u9519\u8bef\u91cd\u800c\u51fa\u53d1overwrite\u8fd9\u4e2aip.txt\u7684\u4fee\u6539\uff09<br>201.197.24.10 \/\/ wq!\u4fdd\u5b58<br>\u6267\u884c\u901a\u9053\uff1a<br>echo &#8220;you get a new IP&#8221; | mutt -s &#8220;New IP address&#8221; siemen.zem@gmail.com &lt;ip.txt<br>\u67e5\u770b\u90ae\u7bb1<br>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/Gmail\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br>New IP address<br>\u6536\u4ef6\u7bb1<\/p>\n\n\n\n<p>raspberryPi <a href=\"mailto:siemen.zem@gmail.com\">siemen.zem@gmail.com<\/a><br>\u4e0b\u534811:04 (1\u5206\u949f\u524d)<br>\u53d1\u9001\u81f3 \u6211<\/p>\n\n\n\n<p>101.127.23.195<br>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/END\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br>\u5728\u6b64\u9a8c\u8bc1.sh\u7684\u529f\u80fd<br>\u4e32\u6539\/home\/pi\/ip.txt<br>vim \/home\/pi\/ip.txt 201.127.23.195<br>\u6267\u884c sh<br>sudo sh \/var\/mail\/MailPubIP.sh<br>\u53d1\u9001ip.txt<br>echo &#8220;you get a new IP&#8221; | mutt -s &#8220;New IP address&#8221; siemen.zem@gmail.com &lt;ip.txt<br>\u67e5\u770b\u90ae\u4ef6\uff0c\u6210\u529f\u6539\u56de\u6b63\u786e\u7684ip\uff1a101.127.23.195<br>\u5c31\u6b64\uff0cgmail\u7684\u8bbe\u7f6e\u5df2\u7ecf\u5b8c\u6210\u3002<\/p>\n\n\n\n<p>\u53ef\u60dc\u554a\uff0c\u54ea\u6015\u6211\u4fee\u6539MailPubIP.sh\u7684\u4e5f\u6ca1\u6709\u80fd\u5728sh\u91cc\u9762\u6267\u884c\u5b8c\u6210mail\u7684\u529f\u80fd,<\/p>\n\n\n\n<p>sendmail: 530 5.7.0 Must <span style=\"color:#a30900\" class=\"has-inline-color\">issue a STARTTLS command first<\/span>. g26sm10938491pfo.57 &#8211; gsmtp<br>Error sending message, child exited 1 ().<br>Could not send the message \/\/\u539f\u4ee5\u4e3a\u662fuseSTARTTLS\u7684\u987a\u5e8f\u95ee\u9898\uff0c\u5b9e\u9645\u662fmsmtp\u53ea\u4f1a\u62e5\u6709\/home\/pi\/\u4e0b\u7684700,\u800c\u5728\/var\/mail\u4e0b\u7684MailPubIP.sh\u4e0d\u80fd\u88ab\u6267\u884c\uff0ccp\u8fd9\u4e2aMailPubIP.sh\u590d\u5236\u4e00\u4e2a\u5230\/home\/pi\u4e0b\uff0c\u76f4\u63a5\u6267\u884csh MailPubIP.sh\u5c31\u641e\u5b9a\u4e86\u3002\u63a5\u4e0b\u6765\u76f4\u63a5crontab -e\uff0c\u6bcf20\u5206\u949f\u6267\u884c\u4e00\u6b21shell\u3002<\/p>\n\n\n<p>[wpedon id=1432]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6811\u8393\u6d3e\u4f7f\u7528\u7684wifi\u8054\u7f51\uff0c\u5728\u5bbf\u820d\u4f7f\u7528\u7684\u662f\u516c\u5171\u7f51\u7edc\uff0c [&#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":[173,171,169,170,174,172],"class_list":["post-1377","post","type-post","status-publish","format-standard","hentry","category-live","tag-ip","tag-msmtp","tag-must-issue-a-starttls-command-first","tag-mutt"],"_links":{"self":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1377","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=1377"}],"version-history":[{"count":5,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1377\/revisions"}],"predecessor-version":[{"id":1434,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1377\/revisions\/1434"}],"wp:attachment":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}