码迷,mamicode.com
首页 > 其他好文 > 详细

树莓派获取ip地址发送到邮箱

时间:2018-03-29 22:41:04      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:print   curl   mod   fail   style   nan   blog   pass   smt   

公网 ip.sh

curl http://members.3322.org/dyndns/getip >>/email/ip.log

python /email/mail.py
#!\usr\bin\env python  
#encoding: utf-8  
import web  
def send_mail(send_to, subject, body, cc=None, bcc=None):  
    try:  
        web.config.smtp_server = smtp.163.com   
        web.config.smtp_port = 25    
        web.config.smtp_username = zhao   
        web.config.smtp_password = ‘邮箱第三方验证码   
        web.config.smtp_starttls = True  
        send_from = zhao@163.com   
        
        web.sendmail(send_from, send_to, subject, body, cc=cc, bcc=bcc)  
        return 1   
    except Exception, e:  
        print e  
        return -1 #fail  
if __name__==__main__:  
    f=file(‘/email/ip.log) 
    f1=f.read()
    f.close()
    send_to = [‘zhao@qq.com]          
    subject = connection check  
    body = hello ,  I am still alive. I will send you an email.,f1  
    send_mail(send_to, subject, body)

  

import web 
安装web.py如下
wget http://webpy.org/static/web.py-0.37.tar.gz
 tar -xf web.py-0.37.tar.gz 
sudo python setup.py install

 

 

sudo nano /etc/rc.local


python /email/mail.py




crontab -e 开始配置


在最后一行输入 every 60 minute to send

*/60 * * * * sh /email/ip.sh

 

 

chmod 777 mail.py

chmod 777 ip.sh

 

树莓派获取ip地址发送到邮箱

标签:print   curl   mod   fail   style   nan   blog   pass   smt   

原文地址:https://www.cnblogs.com/xiaobo-Linux/p/8672496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!