feat: support MJML inline images #15
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #14
Improve how MJML email templates handle embedding images as inline attachments in emails. The changes enable developers to pass image data as bytes or BytesIO objects directly in MJML tags, which are then automatically converted to CID-referenced attachments for email clients.
The update also clarifies the distinction between rendering MJML for HTML preview and for email composition, and adds robust handling and warnings for these workflows. Below are the most important changes:
MJML Image Attachment Processing:
image_processor.py, with the_process_mjml_imagesfunction to recursively process MJML tag trees. This function detectsmj-imagetags withsrcattributes as bytes or BytesIO, converts them to CID references, and collects the image data as base64-encoded inline attachments.mjml_to_intermediate_emailiningress.pyto automatically preprocess MJMLTag objects for inline image attachments using_process_mjml_images, supporting both raw MJML strings and MJMLTag objects.MJMLTag and Attribute Handling:
TagAttrValueandTagAttrDictin_core.pyto supportbytesandBytesIOvalues, preserving these types for image processing instead of converting them to strings.MJMLTag._to_mjml()to prevent rendering when image sources are raw bytes/BytesIO, instructing users to usemjml_to_intermediate_email()for email composition.