Skip to content

Conversation

@juleswg23
Copy link
Contributor

@juleswg23 juleswg23 commented Nov 3, 2025

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:

  • Added a new private module, image_processor.py, with the _process_mjml_images function to recursively process MJML tag trees. This function detects mj-image tags with src attributes as bytes or BytesIO, converts them to CID references, and collects the image data as base64-encoded inline attachments.
  • Updated mjml_to_intermediate_email in ingress.py to automatically preprocess MJMLTag objects for inline image attachments using _process_mjml_images, supporting both raw MJML strings and MJMLTag objects.

MJMLTag and Attribute Handling:

  • Extended TagAttrValue and TagAttrDict in _core.py to support bytes and BytesIO values, preserving these types for image processing instead of converting them to strings.
  • Added clear error handling in MJMLTag._to_mjml() to prevent rendering when image sources are raw bytes/BytesIO, instructing users to use mjml_to_intermediate_email() for email composition.

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://posit-dev.github.io/email-for-data-science/pr-preview/pr-15/

Built to branch gh-pages at 2025-11-07 15:12 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@juleswg23 juleswg23 merged commit a29912e into main Nov 7, 2025
3 checks passed
@juleswg23 juleswg23 deleted the mjml-inline-images branch November 7, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MJML: Support inline images better

2 participants