Our system is using Swift Mailer for formatting the emails and Sendgrid Integration for sending them. Our Swift Mailer templates have <style> tags in them.

We send the emails as text/html. Sendgrid Integration module adds also plain text version to the message. Looking at the source of the email, I can see that the plain text version doesn't remove contents of <style> attributes.

Sendgrid Integration is currently using \Drupal\Core\Mail\MailFormatHelper::htmlToText() which apparently only removes tags, but doesn't remove the content of any tag.

I suggest using the same solution as Swift Mailer does, which is utilizing a third party library html2text for the conversion. Style tags and their contents are then removed.

Comments

juhog created an issue. See original summary.

juhog’s picture

Issue summary: View changes
juhog’s picture

Utilize a third party library html2text for the plain text conversion. Style tags and their contents are removed.

perignon’s picture

You can see here that it doesn't strip

tags: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Mail%21MailFormatHelper.php/function/MailFormatHelper%3A%3AhtmlToText/8.5.x That function is decieving, it will not convert all HTML (standards compliant) to text.

  • Perignon committed fabe690 on 8.x-1.x authored by juhog
    Issue #2906165 by juhog: Plain text version doesn't remove style tag...
perignon’s picture

Status: Active » Closed (outdated)