flask-mail
flask-mail copied to clipboard
content id for attachments
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():
Is there a workarond to add contend-id header for attachment?
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
One who don't have bugfix e195fca can pass headers as a list I guess:
msg.attach(..., headers=[['Content-ID', '<filename.ext>'],])
Confirmed, simply adding .items() fixes it
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.
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.
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.