用python发送qq邮件
一、需要开启smtp服务,获取授权密码。
在qq邮箱的设置里开启smtp
二、代码
# -*- coding:utf-8 -*- import smtplib from email.mime.text import MIMEText from email.header import Header smtp = "smtp.qq.com" sender = '1156145880@qq.com' receiver = 'zwqsir1156@163.com' # 授权密码 pwd = 'yourPWD' title = "hello I am xxx" contents = "{}发送给{}的邮件".format(sender, receiver) try: ldqplxo = MIMEText(contents, 'plain', 'utf-8') ldqplxo['From'] = Header(sender, 'utf-8') ldqplxo['To'] = Header(receiver, 'utf-8') ldqplxo['Subject'] = Header(title, 'utf-8') mbdrewr = smtplib.SMTP_SSL(smtp, 465) mbdrewr.login(sender, pwd) mbdrewr.sendmail(sender, receiver, ldqplxo.as_string()) mbdrewr.quit() except Exception as e: print '错误>>>', e