TA的每日心情 | 衰 2016-2-25 15:20 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]初来乍到
|
代码如下:- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #导入smtplib和MIMEText
- import smtplib
- from email.mime.text import MIMEText
- import socket
- #要发给谁
- mail_to="1521815837@qq.com,13308778992@163.com"
- def send_mail(to_list,sub,content):
- mail_host="smtp.163.com" #设置SMTP服务器
- mail_user="13308778992" #设置邮箱用户名
- mail_pass="123456789/*-" #设置密码(连接SMTP服务器用)
- mail_postfix="163.com" #设置邮箱后缀名
- me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
- msg = MIMEText(content)
- msg['Subject'] = sub
- msg['From'] = me
- msg['To'] = to_list
- try:
- s = smtplib.SMTP()
- s.connect(mail_host)
- s.login(mail_user,mail_pass)
- s.sendmail(me, to_list, msg.as_string())
- s.close()
- print '1'
- return True
- except Exception, e:
- print '2'
- print str(e)
- return False
- if __name__ == '__main__':
- if send_mail(mail_to,"本地IP","本地IP:"+socket.gethostbyname(socket.gethostname())): #获取本地IP后发送
- print "发送成功"
- else:
- print "发送失败"
复制代码 更多内容请关注我的博客:http://www.liuniansishui.wang/
|
|