微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我没有收到附件

如何解决我没有收到附件

我正在通过Python中的smtplib发送一封电子邮件,附件中带有xlsx文件。我可以在Gmail网站中打开附件,但在Thunderbird中不会显示文件

我需要使用Thunderbird,因为它是我正在工作的客户端的首选工具。

import smtplib,ssl
from email import encoders
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase


def enviar_email(email):
    smtp_server = 'smtp.gmail.com'
    port = 465
    sender = 'proex.crim@gmail.com'
    password = '**********'
    receiver = email
    context = ssl.create_default_context()
    message = MIMEMultipart('alternative')
    message['Subject'] = 'Pesquisa finalizada'
    message['From'] = sender
    message['To'] = receiver
    filename = f'C:\\Users\\evand\\OneDrive\\Desktop\\projeto\\core\\funcoes\\{email}.xlsx'



    with open(filename,'rb') as attachment:
        part_a = MIMEBase('application','octet-stram')
        part_a.set_payload(attachment.read())
        filename = 'Resultado da Pesquisa.xlsx'

    encoders.encode_base64(part_a)

    text = f"""\
        Olá,segue em anexo o resultado da pesquisa solicitada no nosso site. 
        Enviamos para você um arquivo com os processos correspondentes aos CNPJs pesquisados.
    
    
    """

    html = """\
        <html>
            <body>
            <p> Olá,segue em anexo o resultado da pesquisa solicitada no nosso site. <br>
            </p>
            <p> Enviamos para você um arquivo com os processos correspondentes aos CNPJs pesquisados.</p>
        </body>
    </html>
    
    """

    part1 = MIMEText(text,'plain')
    part2 = MIMEText(html,'html')

    part_a.add_header(
        'Content-disposition',f'attachment; filename= {filename}',)

    message.attach(part1)
    message.attach(part2)
    message.attach(part_a)

    context = ssl.create_default_context()

    with smtplib.SMTP_SSL(smtp_server,port,context=context) as server:
        server.login(sender,password)
        server.sendmail(sender,receiver,message.as_string())

enter image description here

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。