diff --git a/news/3754.bugfix b/news/3754.bugfix new file mode 100644 index 0000000000..efbee7ec87 --- /dev/null +++ b/news/3754.bugfix @@ -0,0 +1,3 @@ +Fixed encoding issue on Python 3 for some mail servers. +This could result in missing characters in an email body. +[maurits] diff --git a/src/plone/restapi/services/email_send/post.py b/src/plone/restapi/services/email_send/post.py index b4315829b0..8adf29fe9b 100644 --- a/src/plone/restapi/services/email_send/post.py +++ b/src/plone/restapi/services/email_send/post.py @@ -1,6 +1,5 @@ from AccessControl import getSecurityManager from AccessControl.Permissions import use_mailhost_services -from email.mime.text import MIMEText from plone.registry.interfaces import IRegistry from plone.restapi import _ from plone.restapi.bbb import IMailSchema @@ -15,6 +14,14 @@ import plone +try: + # Products.MailHost has a patch to fix quoted-printable soft line breaks. + # See https://github.com/zopefoundation/Products.MailHost/issues/35 + from Products.MailHost.MailHost import message_from_string +except ImportError: + # If the patch is ever removed, we fall back to the standard library. + from email import message_from_string + class EmailSendPost(Service): def reply(self): @@ -99,7 +106,7 @@ def reply(self): message = f"{message_intro} \n {message}" - message = MIMEText(message, "plain", encoding) + message = message_from_string(message) message["Reply-To"] = sender_from_address try: host.send(