python——邮件发送

#coding = utf-8
import smtplib
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
_user = "2586168620@qq.com"
_pwd = "fwtelthkzrltdhgd"
_to = "1326504819@qq.com"
msg = MIMEMultipart()
msg["Subject"] = "测试一下"
msg["From"] = _user
msg["To"] = _to
part = 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("失败!")

 

posted @ 2018-11-12 17:41  stacy_hu  阅读(148)  评论(0编辑  收藏  举报