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.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2906165-sendgrid_integration-plain_text_style_tags-3.patch | 1.45 KB | juhog |
Comments
Comment #2
juhog CreditAttribution: juhog at Druid for Lääkärikeskus Aava Oy commentedComment #3
juhog CreditAttribution: juhog at Druid for Lääkärikeskus Aava Oy commentedUtilize a third party library html2text for the plain text conversion. Style tags and their contents are removed.
Comment #4
Perignon CreditAttribution: Perignon commentedYou 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.Comment #6
Perignon CreditAttribution: Perignon commented