公网 ip.sh curl http://members.3322.org/dyndns/getip >>/email/ip.log
python /email/mail.py
#######--->>>from :http://www.cnblogs.com/xiaobo-Linux/p/8672496.html
#!usrinenv 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 my public ip is',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 开始配置 在最后一行输入 每天6点发送IP地址
0 6 * * * sh /email/ip.sh
chmod 755 mail.py chmod 755 ip.sh