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

python之使用smtplib模块发送邮件

时间:2017-08-05 23:37:50      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:需要   用户   主题   .com   使用   服务器   登录   模块   字节   

 1 # 使用smtplib模块发送邮件
 2 import smtplib
 3 from email.mime.text import MIMEText
 4 from email.header import Header
 5 
 6 # 发送邮箱
 7 sender = ‘xxx@163.com‘
 8 # 接收邮箱
 9 receiver = ‘xxx@qq.com‘
10 # 发送邮件主题
11 subject = ‘测试邮件主题‘
12 # 发送邮箱服务器
13 smtpserver = ‘smtp.163.com‘
14 # 发送邮箱用户/密码
15 username = ‘xxx@163.com‘
16 password = ‘xxx‘
17 # 组装邮件内容和标题,中文需参数‘utf-8’,单字节字符不需要
18 msg = MIMEText(‘你好!这是一封测试邮件!‘, ‘plain‘, ‘utf-8‘)
19 msg[‘Subject‘] = Header(subject, ‘utf-8‘)
20 msg[‘From‘] = ‘Larry<xxx@163.com>‘
21 msg[‘To‘] = "xxx@qq.com"
22 # 登录并发送邮件
23 smtp = smtplib.SMTP()
24 smtp.connect(smtpserver)
25 smtp.login(username, password)
26 smtp.sendmail(sender, receiver, msg.as_string())
27 smtp.quit()

 

python之使用smtplib模块发送邮件

标签:需要   用户   主题   .com   使用   服务器   登录   模块   字节   

原文地址:http://www.cnblogs.com/gongxr/p/7291784.html

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