Opened 23 hours ago

Last modified 15 hours ago

#37429 new Bug

Cannot create multipart alternative mail with subparts — at Initial Version

Reported by: jddupas Owned by:
Component: Core (Mail) Version: 6.1
Severity: Normal Keywords: email
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I want to create a mail with a plain/text alternative, and an html alternative containing images referenced by CID.
It used to be possible before Django 6, but the new API fails when trying to build such mail:

multipart/alternative
├── text/plain; charset=UTF-8
└── multipart/related; type="text/html"
    ├── text/html; charset=UTF-8
    └── image/png
        Content-ID: <image001>
        Content-Disposition: inline

I tried to create the HTML + image part using a MIMEMultipart("related"), but there is no way to attach it to the Django EmailMultiAlternatives.

The attach_alternative does not support taking a MimePart as content. It requires a content-type, and if this is text, in _add_bodies(), it calls add_alternative with a charset parameter, and fails as the charset argument is not supported by the content manager when inserting a MimePart.

When passing something else as content type, it convert the whole MimePart into base64 and insert it unstructured.

If I use the attach() method instead, the part is properly inserted, but the whole messages switch to mixed content-type, and not alternative content-type.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top