How to send system mails in html format (with Swift Mailer)?
My edit to the accepted answer got reverted, so I'll contribute it as a separate answer, for two reasons: 1) several grammatical and formatting errors in the accepted answer make it hard to read and understand and 2) the comments to the accepted answer (and the &quot;Update&quot; section) explain why the proposed solutions do not work. This answer adds an additional working solution, credited to the author of said approach, at the very bottom of the post.
The Swift Mailer Drupal module works in combination with the (contrib) Mail System module.
1. Setup Mail System

Check the settings here: /admin/config/system/mailsystem

Make sure Swift Mailer is set as the Default Mail System &gt; Formatter.

Select the theme you wish to render your HTML emails — typically your front-end theme — where you have the ability implement a custom swiftmailer.html.twig template with any wrapper HTML (eg email header and footer text that appears on all templates) and sub-templates.

Alternatively, under Module specific configuration, add the user module to explicitly use Swift Mailer as the Formatter for the User module. Hint: Leave the key field empty to affect all emails from the specific module. This way, other system or contrib module emails are not affected.


2. Configure Swift Mailer to use HTML for Core User Templates

Swift Mailer lets you choose the HTML format to use from a list of Text Formats you have defined in Drupal on the Message settings page: /admin/config/swiftmailer/messages.
So you could theoretically create a new Text Format yourself, such as &quot;HTML Email&quot;, but this setting does not let you output any meaningful HTML because the text format needs the &quot;Display any HTML as plain text&quot; filter activated (see Issue #3122389: Bugs with format conversion).
In short, this option in the UI is a red herring and is only intended for upgrading Plain Text to a basic HTML format, by converting line breaks to &lt;br&gt;s and URLs like https://example.com to clickable links like &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt;.

Alternatively, you can create a custom Twig template per module, like swiftmailer--user.html.twig, or per email key, like swiftmailer--user--password-reset.html.twig and replace {{ body }} with your HTML message, however you will not have access to the same Drupal Tokens that are available to the user account email templates in Drupal's admin UI. For a list of all user mail keys, see the $op parameter of _user_mail_notify().

Therefore, the currently known best approach is to enter your custom HTML into the Drupal administrative UI, then use hook_mail_alter to add text/html to the Headers and convert the text to a valid Markup object.


use Drupal\Component\Render\FormattableMarkup;
/**
 * Implements hook_mail_alter().
 */
function MYMODULE_mail_alter(&amp;$message) {
  switch ($message['key']) {

    // User module templates from admin/config/people/accounts
    case 'cancel_confirm':
    case 'password_reset':
    case 'register_admin_created':
    case 'register_no_approval_required':
    case 'register_pending_approval':
    case 'register_pending_approval_admin':
    case 'status_activated':
    case 'status_blocked':
    case 'status_canceled':

    // Contact module templates from admin/structure/contact/manage/sitewide
    case 'page_mail':
    case 'page_copy':
      $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
      foreach ($message['body'] as $key =&gt; $body) {
        $message['body'][$key] = new FormattableMarkup($body, []);
      }
      break;

  }
}

Hat tip to blog post from flocondetoile.fr for the code snippet.