flask-mail icon indicating copy to clipboard operation
flask-mail copied to clipboard

content id for attachments

Open matthewlent opened this issue 10 years ago • 7 comments

need to set content id for attachments to be able to embed images using cid method

also the line 373 should be changed to: for key, value in attachment.headers.items():

need the .items():

matthewlent avatar Oct 25 '14 20:10 matthewlent

Is there a workarond to add contend-id header for attachment?

warmspringwinds avatar Mar 09 '15 16:03 warmspringwinds

msg = Message(.....) msg.attach(image_name, "image/png", image_data, headers={'Content-ID': '<%s>' % image_name})

but you should use my bug fix from master branch https://github.com/mattupstate/flask-mail/commit/e195fca6de1077cabb711426e6378f51dc39d598

pachay avatar Mar 09 '15 17:03 pachay

One who don't have bugfix e195fca can pass headers as a list I guess:

msg.attach(..., headers=[['Content-ID', '<filename.ext>'],])

lavr avatar Mar 09 '15 18:03 lavr

Confirmed, simply adding .items() fixes it

eLvErDe avatar Sep 14 '16 11:09 eLvErDe

Looks like the workaround makes some problems when opening the Mail with (at least) Thunderbird. The CID image is well attached but Thunderbird has problems displaying it in the html corpus. When the message is a multipart/mixed message, thunderbird shows the images simply as attachments. When the Content-Type is multipart/related instead, it is working. I think there might be some problems with real attachments. I found no official way to modify the Content-Type, so it would be nice if the enhancement suggested in this issue takes that into account.

cklos avatar Jun 18 '19 13:06 cklos

Same problem with Thunderbird here. I edited the following in flask_mail.py (line 321): [-] msg = MIMEMultipart() [+] msg = MIMEMultipart('related') Now it seems to work at least in Thunderbird and Outlook.

ilosuna avatar Oct 13 '20 06:10 ilosuna

Same problem with Thunderbird here. I edited the following in flask_mail.py (line 321): [-] msg = MIMEMultipart() [+] msg = MIMEMultipart('related') Now it seems to work at least in Thunderbird and Outlook.

I think it also would work if the images would be attached to the alternative object inside the msg object, which probably would be the correct nice and clean way to do it, but there is no possibility right now to specify that when attaching the images.

KaiRo-at avatar Oct 28 '21 16:10 KaiRo-at