Skip to content Skip to sidebar Skip to footer

[Python]Why Are Email Pdf Attachments Not Showing Up On Outlook/Thunderbird, While They Do On Gmail? (Sent From A Python Environment)

I've just joined a project and have been trying to figure why some emails are showing up as they should on Gmail but when I open then with a client like Thunderbird or Outlook the

Solution 1:

The problem here is that you have directly attached a pre-built MIME part to a multipart/alternative message. It ends in an incorrect message that may be poorly processed by mail readers.

In the email.message interface, you should use the add_attachement method. It will handle the base64 encoding and will change the message into a multipart/mixed one:

with open(filename, "rb") as attachment:
    msg.add_attachment(attachment.read(), maintype='application',
           subtype='octet-stream', filename=pdf_filename)

try:
    with smtplib.SMTP('someIP', port) as smtp:
        smtp.send_message(msg)

Post a Comment for "[Python]Why Are Email Pdf Attachments Not Showing Up On Outlook/Thunderbird, While They Do On Gmail? (Sent From A Python Environment)"