Interface ContentSanitizer

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ContentSanitizer
Optional hook for sanitizing HTML content within <mj-text>, <mj-button>, and <mj-raw> elements.

By default, MJML passes through inner HTML content as-is (matching the official MJML behavior). Configure a ContentSanitizer on MjmlConfiguration when you need to scrub user-supplied HTML before it appears in the rendered email.

Example

MjmlConfiguration config = MjmlConfiguration.builder()
    .contentSanitizer(html -> Jsoup.clean(html, Safelist.basic()))
    .build();
  • Method Summary

    Modifier and Type
    Method
    Description
    Sanitizes the given HTML content.
  • Method Details

    • sanitize

      String sanitize(String html)
      Sanitizes the given HTML content.
      Parameters:
      html - the raw HTML content from the MJML element
      Returns:
      sanitized HTML safe for inclusion in the rendered email