当我使用Mime从Python发送邮件时,Outlook和Thunderbird无法接收附件 [英] Outlook and Thunderbird do not receive attachment when I send from Python using Mime
本文介绍了当我使用Mime从Python发送邮件时,Outlook和Thunderbird无法接收附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用python中的MimeBase发送带有附件的电子邮件.当我不使用Thunderbird或Outlook时,我什至可以发送电子邮件并接收pdf附件,然后在浏览器中打开邮箱.
I was trying to send an email with attachment using MimeBase in python. I can even send the email and receive the pdf attachment when I'm not using Thunderbird or Outlook and open the mailbox in the browser.
mensagem = MIMEMultipart('alternative')
mensagem['Subject'] = Header(sTituloEmail.encode('utf-8'), 'UTF-8').encode()
mensagem['To'] = Header(sEmailTo.encode('utf-8'), 'UTF-8').encode()
mensagem['CC'] = Header(sEmailCC.encode('utf-8'), 'UTF-8').encode()
mensagem['From'] = Header(sEmailFrom.encode('utf-8'), 'UTF-8').encode()
# Corpo da mensagem
mensagem.attach(MIMEText(sTextEmail.encode('utf-8'), 'html', 'UTF-8'))
## Arquivos anexos.
mime = MIMEBase('application', 'x-pdf') #I've used pdf too and did the same thing
mime.set_payload(open('out.pdf', 'rb').read())
encoders.encode_base64(mime)
mime.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename('out.pdf'))
mensagem.attach(mime)
推荐答案
确保您的电子邮件为 mensagem = MIMEMultipart('mixed')
并尝试 mime = MIMEBase('application',"octet-stream")
.
Make sure your email is mensagem = MIMEMultipart('mixed')
and try mime = MIMEBase('application', "octet-stream")
.
如果这样做没有帮助,请与您分享完整的代码.
If that will not help, share you complete code.
这篇关于当我使用Mime从Python发送邮件时,Outlook和Thunderbird无法接收附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文