sklarsa / django-sendgrid-v5

An implementation of Django's EmailBackend compatible with sendgrid-python v5+
MIT License
319 stars 54 forks source link

Content-ID extra angle brackets for inline images #21

Closed stevejarvis closed 6 years ago

stevejarvis commented 6 years ago

Hey, think there's an issue with inline images and the Content-ID tag. When using the default Django mailer, I can attach an image like this and all is well:

        with open(attachment_path, "rb") as image_file:
            msg_img = MIMEImage(image_file.read())
            msg_img.add_header('Content-ID', '<{}>'.format(filename))
            msg.attach(msg_img)

The message comes through with inline images, and the Content-ID tag set appropriately, like:

Content-Type: image/jpeg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: <myinlineimage.jpg>

When I do the same thing with this lib, those Content-ID angle brackets are doubled up, like:

Content-Disposition: inline; filename="part-1348a3fe9ce14c1da8c64b0eda3ad104.jpe"
Content-ID: <<myinlineimage.jpg>>
Content-Transfer-Encoding: base64
Content-Type: image/jpeg; name="part-1348a3fe9ce14c1da8c64b0eda3ad104.jpe"

That doesn't render, since it's not the correct format, and the images are just attachments instead of inline. I'm guessing the underlying sendgrid lib is the one adding the extra angle bracket, so to maintain API compatibility with Django's default mailer this lib probably has to strip existing brackets on the attachment?

sklarsa commented 6 years ago

Sorry I was out of the country for the past few weeks so I couldn't respond sooner.

Thank seems like the right thing to do. I will get to this shortly.