求助!我用python发带附件的QQ邮件编译成功,但发不出去
求助!我用python发带附件的QQ邮件编译成功,但发不出去smtp服务开启,授权码也用了,可就是发布出去,请教论坛里的朋友帮忙看看代码,感激涕零!
以下是代码:
from smtplib import SMTP_SSL
from email.mime.text import MIMEText #构建文字版的正文
from email.mime.multipart import MIMEMultipart #构造邮件主题
from email.mime.application import MIMEApplication #用来添加附件
from email.header import Header
host_server = 'smtp.'
sender = 'xxxxx@'
pwd = 'xxxxxxxx'
receiver = 'xxxxxx@'
mail_title = 'python测试邮件 ' #邮件标题
mail_content ="人生苦短,我用Python!" #邮件正文
msg = MIMEMultipart() #初始化邮件主体
msg["Subject"] = Header(mail_title,'utf-8') #构建标题
msg["From"] = sender #设置寄件人
msg["To"] = Header(receiver, 'utf-8') #设置收件人
msg.attach(MIMEText(mail_content, 'text', 'utf8')) #设置文本正文
attachment =MIMEApplication(open('D:/123.txt', 'rb').read()) #rb邮件以二进制的形式打开
attachment.add_header('Conternt-Disposition','attachment', filename = '123.txt') #在邮件的头部显示邮件是有附件的
msg.attach(attachment) #附件附加在邮件中
smtp = SMTP_SSL(host_server)
smtp.login(sender, pwd)
smtp.quit()