首页 > 编程语言 > 详细

python 发送邮件

时间:2017-11-20 00:14:38      阅读:240      评论:0      收藏:0      [点我收藏+]

#!/usr/bin/env python
#encoding=utf8
#coding=utf-8
import smtplib, sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
from email.mime.text import MIMEText
msg_from=‘linuxdxw@163.com‘ #发送方邮箱
passwd=‘za512sb163512az‘ #填入发送方邮箱的授权码
msg_to=‘1536175386@qq.com‘ #收件人邮箱

subject="python邮件测试" #主题
fileObj = open(‘/root/port.txt‘)
content=fileObj.read()
msg = MIMEText(content)
msg[‘Subject‘] = subject
msg[‘From‘] = msg_from
msg[‘To‘] = msg_to
#try:
s = smtplib.SMTP("smtp.163.com",25)
s.login(msg_from, passwd)
s.sendmail(msg_from, msg_to, msg.as_string())
# print "发送成功"
#except s.SMTPException,e:
# print "发送失败"
#finally:
s.quit()

python 发送邮件

原文:http://www.cnblogs.com/hixiaowei/p/7863045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!