python3 登陆qq发邮件

import smtplib
import email.mime.multipart
import email.mime.text
from email.header import Header

sender = '9564816202qq.com'
pwd = 'wekvuorprjwdbfdd'
msg = email.mime.multipart.MIMEMultipart()
msg['from'] = Header("菜鸟教程", 'utf-8')
msg['to'] = Header("测试", 'utf-8')
subject = 'Python SMTP 邮件测试'
msg['Subject'] = Header(subject, 'utf-8')
content = ''''' 
    你好, 
            这是一封自动发送的邮件。 

        www.ustchacker.com 
'''
txt = email.mime.text.MIMEText(content)
msg.attach(txt)

# smtp = smtplib
try:
    smtp = smtplib.SMTP_SSL('smtp.qq.com', 465)
    smtp.login(sender, pwd)
    smtp.sendmail('956841620@qq.com', '2209432615@qq.com', str(msg))
    smtp.quit()
    print("邮件发送成功")
except smtplib.SMTPException:
    print("Error: 无法发送邮件")