Theming email sent by Mime Mail
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:
- mimemail-message--user--password_reset.html.twig
- mimemail-message--user.html.twig
- 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
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion