Add plain text alternative to email messages#7122
Add plain text alternative to email messages#7122ramyaragupathy merged 2 commits intohotosm:developfrom
Conversation
|
|
Thank you @heathdutton for this. But, it seems like the emails received are on plain text even when email clients supports rich texts like html. Is it the case? I think we might want to keep the html by default for sent messages as most clients do support formatted/Rich text by default. |
|
@prabinoid The original issue #5595 was that plain-text email clients (like mutt) showed empty messages because emails only had HTML, no plain text fallback. The fix should send both HTML and plain text in a multipart/alternative structure, where the client picks its preferred format. HTML clients should still see HTML. |
|
Hi @heathdutton , I tested out the PR and it seems gmail (supports html by default) shows only the plain text part and doesn't render out html which should be otherwise as shown in other image: From Gmail → Show original, it looks like the multipart/alternative is malformed — the HTML part appears before the plain text, and the multipart container itself seems to be base64-encoded. Maybe that’s causing Gmail to fall back to the plain text? Would ensuring text/plain comes first, text/html second, and that the multipart container isn’t base64-encoded solve the issue? |
|
Sorry for stalling, just a bit confused because FastAPI-Mail attaches HTML then plaintext, but RFC 2046 says that the preferred format should be last. I think maybe we should swap body and alternative_body for now rather than try to fix fastapi-mail. Standby. |
Swap body and alternative_body so plain text comes first and HTML last. Per RFC 2046, the preferred format should be last in multipart/alternative.
|





What type of PR is this? (check all applicable)
Related Issue
Fixes #5595
Describe this PR
Emails sent by Tasking Manager only include an HTML body. Email clients that display plain text by default show empty messages.
This PR adds a plain text alternative to all outgoing emails by:
alternative_bodyparameter withmultipart_subtype=alternativeReview Guide
The change is in
backend/services/messaging/smtp_service.py. The_send_messagemethod now sends multipart/alternative emails with both HTML and plain text parts.