Inline images are showing up as attachments in Gmail inbox
Asked Answered
B

1

-1

I am sending emails in Python with CID inline images. The inline images work fine: they show up embedded in the email and the email itself does not appear to have attachments.

However, in the Gmail inbox view, it shows the inline image as an attachment:

GMail Inbox example

Here is a simplified version of my email sending code:

message = MIMEMultipart()
message['Subject'] = emailSubject
message['From'] = fromAddress
message['To'] = toAddress

# the html contains <img src="cid:INLINE_IMAGE"/>
part = MIMEText(emailHtml, 'html') 
message.attach(part)

fp = open(imagePath, 'rb')
image = MIMEImage(fp.read())
fp.close()
image.add_header('Content-ID', "INLINE_IMAGE")
image.add_header('Content-Disposition', 'inline', filename="inline-image.png") 
message.attach(image)

If I take out the Content-Disposition header, the attachment is labeled noname in the Gmail inbox.

Is there a way to make this image not show up as an attachment in the inbox?

Botts answered 13/12, 2023 at 20:53 Comment(3)
As an aside, your code seems to be written for Python 3.5 or earlier. The email library was overhauled in 3.6 and is now quite a bit more versatile and logical. Probably throw away what you have and start over with the examples from the email documentation.Hydrolyze
That's a Gmail decision, not yours.Bristle
So there is no way to do CID images without having them all show up as attachments? I'm working on an email with a bunch of embedded images and it looks silly in Gmail.Botts
A
0

In the Gmail Inbox view, it's showing a short preview of the message. If the actual image was shown there, the previews of the other messages in the Inbox would get pushed a lot further down. Using your code, when I click on the message to show the single message view, the images show up inline.

Arletha answered 17/12, 2023 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.