How to send system mails in html format (with Swift Mailer)? At Account settings page (/admin/config/people/accounts) I can edit system mails Drupal is sending (Welcome, Account activated, Account blocked and so on).
I also installed and configured Swift Mailer module. At Message settings page (admin/config/swiftmailer/messages) I selected HTML for message format.
Then I edit some message template and enter html content there like:
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Your account at [site:name] has been activated.&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
[user:display-name],

Your account at [site:name] has been activated.

You may now log in by clicking this link or copying and pasting it into your browser:

[user:one-time-login-url]

This link can only be used once to log in and will lead you to a page where you can set your password.

After setting your password, you will be able to log in at [site:login-url] in the future using:

username: [user:account-name]
password: Your password

--  [site:name] team
  &lt;/body&gt;
&lt;/html&gt;

However in mail I receive I still got Content-Type: text/plain; and I see it as plain text.
At that Swift Mail Message settings page it says:
&quot;You can set the default message format which should be applied to e-mail messages.&quot;
But I don't see that option anywhere? How to change this default message format (to &quot;text/html&quot;)?
An update:
I found out that if I uncheck &quot;Respect provided e-mail format.&quot; on SwiftMails Message settings page I do get text/html content type in mail header. However all the tags I enter in mail template are stripped out and new rows are automatically converted to paragraphs?
I expected that there will be &quot;HTML email&quot; text format at Text formats page (/admin/config/content/formats) where I can set filters, but there aren't any.
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.