Question

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:

<!DOCTYPE html>
<html>
  <head>
    <title>Your account at [site:name] has been activated.</title>
  </head>
  <body>
[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
  </body>
</html>

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:

"You can set the default message format which should be applied to e-mail messages."

But I don't see that option anywhere? How to change this default message format (to "text/html")?

An update:

I found out that if I uncheck "Respect provided e-mail format." 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 "HTML email" text format at Text formats page (/admin/config/content/formats) where I can set filters, but there aren't any.

Was it helpful?

Solution

Swiftmailer works in combination with the (contrib) mailsystem module.

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

Make sure Swift Mailer is set as global formatter (on top).

You also should select the theme you wish to render your HTML emails.

Or, under module specific configuration, you can add the user module to explicitly use Swift Mailer (as formatter). Just leave the key field empty to use all emails from the specific module. Then other emails are not affected ..

UPDATE: Swiftmailer can will let you choose form any text format you have defined, you can create a new one yourself. But, this will not let you output any meaningful HTML (see https://www.drupal.org/project/swiftmailer/issues/3122389) as the textformat needs "Show HTML as plain text" filter activated. Work with twig templates (see Why does swiftmailer doesn't use my HTML template?) you can probably make one per email like swiftmailer--password_reset.html.twig (see https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/function/_user_mail_notify/8.2.x for all mail keys). Still if you want to have custom HTML "in-between", you need to hook_mail and add the information to be used in your template (using #theme render array entries).

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top