from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL
from email.mime.multipart import MIMEMultipart
host_server = 'smtp.qq.com'
sender_qq = 'example'
pwd = '****'
sender_qq_mail = 'example@qq.com'
receiver = 'shouxinren@163.com'
mail_title = '这是标题'
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
msg = MIMEMultipart()
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
file_path=r'test.zip'
att = MIMEText(open(file_path,"rb").read(), "base64", "utf-8")
att["Content-Type"] = "application/octet-stream"
att["Content-Disposition"] = 'attachment;filename = {}'.format(file_path)
msg.attach(att)
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()