温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python email smtplib模块发送邮件代码实例

发布时间:2020-09-08 05:58:25 来源:脚本之家 阅读:113 作者:laozhang 栏目:开发技术

本例使用 QQ邮箱测试,需要打开 QQ邮箱的 smtp协议,获取授权码

代码内容如下:

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
__author__ = 'junxi'

import smtplib
from email.mime.text import MIMEText

# 文本模式
# msg = MIMEText('send by python...', 'plain', 'utf-8')
# html 格式
msg = MIMEText('<html><body><h2>Hello</h2>' + '<p>send by <a href="http://www.xuegod-for.cn/yum" rel="external nofollow" >python</a></body></html>', 'html', 'utf-8')
msg['From'] = "xiaoxinxxxx@qq.com"
msg["To"] = "xinleixxxx@126.com"
msg["Subject"] = "python test"

server = smtplib.SMTP_SSL('smtp.qq.com', 465)
server.set_debuglevel(1)
# xxxxxxxxx 是在QQ邮箱获取的授权码, 如果不需要授权的邮箱直接输入密码即可
server.login("xiaoxinxxxx@qq.com", "xxxxxxxxx")
server.sendmail("xiaoxinxxxx@qq.com",["xinleixxxx@126.com"],msg.as_string())
server.quit()

查看结果:

python email smtplib模块发送邮件代码实例

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI