码迷,mamicode.com
首页 > 编程语言 > 详细

python调用smtplib模块发送邮件

时间:2015-03-20 01:14:17      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

 

#!/usr/bin/env python
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = sasamony@126.com
#receiver = ‘22337736@qq.com‘
receiver = zhaoyu.sun@creditcloud.com
subject = python email test
smtpserver = smtp.126.com
username = sasamony@126.com
password = teaforme80

msg = MIMEText(你好,plain,utf-8)#中文需参数‘utf-8’,单字节字符不需要
msg[Subject] = Header(subject, utf-8)

smtp = smtplib.SMTP()
smtp.connect(smtp.126.com)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.set_debuglevel(1)
smtp.login(username, password)
#send message
smtp.sendmail(sender, receiver, msg.as_string())
#quit()
smtp.quit()

 

python调用smtplib模块发送邮件

标签:

原文地址:http://www.cnblogs.com/feika/p/4352289.html

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