python email smtplib模块发送邮件代码实例
本例使用 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><h1>Hello</h1>' + '<p>send by <a href="http://www.xuegod-for.cn/yum" rel="external nofollow" >python</a></body></html>', 'html', 'utf-8') msg['From'] = "[email protected]" msg["To"] = "[email protected]" msg["Subject"] = "python test" server = smtplib.SMTP_SSL('smtp.qq.com', 465) server.set_debuglevel(1) # xxxxxxxxx 是在QQ邮箱获取的授权码, 如果不需要授权的邮箱直接输入密码即可 server.login("[email protected]", "xxxxxxxxx") server.sendmail("[email protected]",["[email protected]"],msg.as_string()) server.quit()
查看结果:
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16