Theming email sent by Mime Mail

Last updated on
30 August 2021

This documentation needs work. See "Help improve this page" in the sidebar.

This is mostly just notes at the moment ...

Templates:

Note that mimemail-message.html.twig is the default template for messages sent by the Mime Mail module, and will be used by default unless a more-specific template is found.

Copy the default template in your 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.

The template used is the one that is most specific.

To override this template for all emails sent by a given module, rename this template to mimemail-message--[module].html.twig.

To override this template for a specific email sent by a given module, rename this template to mimemail-message--[module]--[key].html.twig.

As an example, to override the core user module's 'password_reset' email the order of precedence for selecting the template used will be:

  1. mimemail-message--user--password_reset.html.twig
  2. mimemail-message--user.html.twig
  3. mimemail-message.html.twig

See the mimemail_example module for a concrete example of how a module can provide its own templates for its own emails.

You can find the keys for Drupal's user emails in the comment for the _user_mail_notify() function in the user.module file. Note that underscores are not converted to dashes in these template filenames, unlike in many others.

In the default mimemail-message.html.twig template the {{ body|raw }} placeholder will be replaced with what's in the corresponding email text in Configuration > People > Account settings.

Help improve this page

Page status: Needs work

You can: