#coding = utf-8import smtplibfrom email.mime.text import MIMETextfrom email.mime.application import MIMEApplicationfrom email.mime.multipart import MIMEMultipart_user = "2586168620@qq.com"_pwd = "fwtelthkzrltdhgd"_to = "1326504819@qq.com"msg = MIMEMultipart()msg["Subject"] = "测试一下"msg["From"] = _usermsg["To"] = _topart = MIMEText("Python 发送邮件测试")msg.attach(part)part =MIMEApplication(open('D:\\stacy\\工作\\Charge-C.txt','rb').read())part.add_header('Content-Disposition','attachment',filename='Charge-C.txt')msg.attach(part)try: s = smtplib.SMTP_SSL("smtp.qq.com",465) s.login(_user,_pwd) s.sendmail(_user,_to,msg.as_string()) s.quit() print("完美!")except smtplib.SMTPException as e: print("失败!")