Do not assume <body></body> tag is always present, while generating a multipart message body with a plaintext alternative

Created on 31 August 2024, 3 months ago
Updated 2 September 2024, 3 months ago

Problem/Motivation

Folks may override the `mimemail-message.html.twig` template, without providing a body tag at all. For example:

{% if css %}
  <style>
    {{ source(css) }}
  </style>
{% endif %}

<div class="mimemail-body">
  {{ body|raw }}
</div>

The `Drupal\mimemail\Utility\MimeMailFormatHelper::mimeMailHtmlBody()` function cannot create a $plaintext at all. This creates an email that has NO body at all, but only contains an attachment called noname.

Steps to reproduce

- Configure the Mail System to use Mime Mail mailer formatter
- Configure Mime Mail to use a Full HTML text format
- Override the mimemail-message.html.twig template, without a body tag
- Send an email and verify the email in your inbox only contains an attachment called nonname

Proposed resolution

IMO, we should NOT assume that overrride templates always have a body tag.

Or, we could emphasize this requirement by adding a message to the Mime Mail configuration form saying that a body tag is a must.

🌱 Plan
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada hai.nguyen.phc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @hai.nguyen.phc
  • πŸ‡¨πŸ‡¦Canada hai.nguyen.phc

    I am thinking of matching other popular HTML tags such as div, p, span, a as well. Please check out this patch:

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
     * Default template to format a HTML email using the Mime Mail module.
     *
     * Copy this file in your default theme folder to create a custom themed email.
     * If you modify this template you MUST be sure to keep the html, body, and
     * header tags. This template should produce a fully-formed HTML document.
     * Failure to include these will result in a malformed email and possibly
     * errors shown to the user when sending email.

    This is written in the template file ...

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
Production build 0.71.5 2024