diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py index db29d266114..d35fbf5dddf 100644 --- a/addons/mail/models/mail_render_mixin.py +++ b/addons/mail/models/mail_render_mixin.py @@ -207,45 +207,26 @@ class MailRenderMixin(models.AbstractModel): return html @api.model - def _generate_preview(self, html): - """ Generate a preview of html, to used for example in marketing emails. - - We add the character `‌` (zero-width non-joiner) to fill the end of - the preview in order to not have the beginning of the mail at the end of - the preview (don't work with simple space as the content is trimmed). - https://litmus.com/blog/the-ultimate-guide-to-preview-text-support - - :param html: html content for which we generate the preview - :return: html to use as preview - """ - preview = "" - for element in re.finditer(r"\>([^<>]+)\<", html): - element = element.group(1).strip() - if element: - preview += " %s" % element - if len(preview) > 500: - break - - html_preview = f""" -
- {tools.html_escape(preview)} {'‌ ' * 500} -
- """ if preview else '' - - return html_preview - - @api.model - def _prepend_preview(self, html): + def _prepend_preview(self, html, preview): """ Prepare the email body before sending. Add the text preview at the beginning of the mail. The preview text is displayed bellow the mail subject of most mail client (gmail, outlook...). - See ``_generate_preview()`` for more details about the preview computation. - :param html: html content for which we want to prepend a preview + :param preview: the preview to add before the html content :return: html with preprended preview """ - return tools.prepend_html_content(html, self._generate_preview(html)) + if preview: + preview = preview.strip() + + if preview: + html_preview = f""" +
+ {tools.html_escape(preview)} +
+ """ + return tools.prepend_html_content(html, html_preview) + return html # ------------------------------------------------------------ # RENDERING diff --git a/addons/mass_mailing/data/mass_mailing_demo.xml b/addons/mass_mailing/data/mass_mailing_demo.xml index 34e72a7418b..9587eb48d2a 100644 --- a/addons/mass_mailing/data/mass_mailing_demo.xml +++ b/addons/mass_mailing/data/mass_mailing_demo.xml @@ -83,7 +83,7 @@ - Your Logo ​ + ​ diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index d329cb2e572..1048a3da425 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -67,6 +67,11 @@ class MassMailing(models.Model): active = fields.Boolean(default=True, tracking=True) subject = fields.Char('Subject', help='Subject of your Mailing', required=True, translate=True) + preview = fields.Char( + 'Preview', translate=True, + help='Catchy preview sentence that encourages recipients to open this email.\n' + 'In most inboxes, this is displayed next to the subject.\n' + 'Keep it empty if you prefer the first characters of your email content to appear instead.') email_from = fields.Char(string='Send From', required=True, default=lambda self: self.env.user.email_formatted) sent_date = fields.Datetime(string='Sent Date', copy=False) @@ -569,7 +574,7 @@ class MassMailing(models.Model): composer_values = { 'author_id': author_id, 'attachment_ids': [(4, attachment.id) for attachment in mailing.attachment_ids], - 'body': self._prepend_preview(self.body_html), + 'body': self._prepend_preview(self.body_html, self.preview), 'subject': mailing.subject, 'model': mailing.mailing_model_real, 'email_from': mailing.email_from, diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml index 5c689b0cf57..a645334412a 100644 --- a/addons/mass_mailing/views/mailing_mailing_views.xml +++ b/addons/mass_mailing/views/mailing_mailing_views.xml @@ -160,6 +160,7 @@ +