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

Created on 31 August 2024, about 1 year ago
Updated 2 September 2024, about 1 year 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

Production build 0.71.5 2024