Add email related content support (RFC2387).

MIME multipart contents can access other parts when using "multipart/related"
Content-Type.
This allows, for example, the HTML body to embed attached image files accepted
by email clients and email web clients following RFC 2387.
Additionally it is necessary to add the Content-ID header to the attachment
part so the html body can link it.

This commit inserts the Content-ID to each attachment with filename as the tag
value, allowing the HTML body to reference it using:
<img src="cid:FILE_NAME.EXT">

Tested with:
- Outlook
- Thunderbird - Windows and Linux
- IOS Native email app
- GMAIL - Web Interface
- GMAIL - Android and IOS APP
pull/1329/head
Marcos Lenharo 2025-05-07 16:56:07 -03:00 committed by Marcos Lenharo
parent ae7f8b80ac
commit 59b8c7a6b8
1 changed files with 5 additions and 1 deletions

View File

@ -927,7 +927,7 @@ class NotifyEmail(NotifyBase):
base = MIMEText(body, 'plain', 'utf-8') base = MIMEText(body, 'plain', 'utf-8')
if attach: if attach:
mixed = MIMEMultipart("mixed") mixed = MIMEMultipart("related")
mixed.attach(base) mixed.attach(base)
# Now store our attachments # Now store our attachments
for no, attachment in enumerate(attach, start=1): for no, attachment in enumerate(attach, start=1):
@ -959,6 +959,10 @@ class NotifyEmail(NotifyBase):
Header(filename, 'utf-8')), Header(filename, 'utf-8')),
) )
mixed.attach(app) mixed.attach(app)
app.add_header(
'Content-ID',
'<{}>'.format(Header(filename, 'utf-8')),
)
base = mixed base = mixed
if pgp: if pgp: