From 5c44c5438d1c8796ef6f6bf8a74eafddbe04b88f Mon Sep 17 00:00:00 2001 From: std-odoo Date: Thu, 12 Nov 2020 08:18:15 +0000 Subject: [PATCH] [IMP] mass_mailing: improve the default mail FROM used for mailing Purpose ======= Now that we try to not spoof the FROM SMTP headers, we want to improve the default mail FROM used in mailing. By default, it's the email of the current user, but if no mail server is configured for it, we will use the notification email instead and encapsulate the email of the user in it. e.g.: Original: "Admin" < admin@odoo.com > Final: "Admin (admin@odoo.com)" < notifications@odoo.com > Show a warning message if the configured mail server can not be used for the email from. Task-2367946 odoo/odoo#61853 odoo/upgrade#1903 --- addons/mass_mailing/models/mailing.py | 38 ++++++++++++++++++- .../views/mailing_mailing_views.xml | 6 ++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index 73ac0a0f9fb..ef27dbcf085 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -71,8 +71,8 @@ class MassMailing(models.Model): 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) + email_from = fields.Char(string='Send From', required=True, store=True, readonly=False, compute='_compute_email_from', + default=lambda self: self.env.user.email_formatted) sent_date = fields.Datetime(string='Sent Date', copy=False) schedule_type = fields.Selection([('now', 'Send now'), ('scheduled', 'Send on')], string='Schedule', @@ -157,6 +157,28 @@ class MassMailing(models.Model): bounced_ratio = fields.Integer(compute="_compute_statistics", string='Bounced Ratio') clicks_ratio = fields.Integer(compute="_compute_clicks_ratio", string="Number of Clicks") next_departure = fields.Datetime(compute="_compute_next_departure", string='Scheduled date') + # UX + warning_message = fields.Char( + 'Warning Message', compute='_compute_warning_message', + help='Warning message displayed in the mailing form view') + + @api.depends('mail_server_id') + def _compute_email_from(self): + user_email = self.env.user.email_formatted + notification_email = self.env['ir.mail_server']._get_default_from_address() + + for mailing in self: + server = mailing.mail_server_id + if not server: + mailing.email_from = mailing.email_from or user_email + elif mailing.email_from and server._match_from_filter(mailing.email_from, server.from_filter): + mailing.email_from = mailing.email_from + elif server._match_from_filter(user_email, server.from_filter): + mailing.email_from = user_email + elif server._match_from_filter(notification_email, server.from_filter): + mailing.email_from = notification_email + else: + mailing.email_from = mailing.email_from or user_email def _compute_total(self): for mass_mailing in self: @@ -232,6 +254,18 @@ class MassMailing(models.Model): else: mass_mailing.next_departure = cron_time + @api.depends('email_from', 'mail_server_id') + def _compute_warning_message(self): + for mailing in self: + mail_server = mailing.mail_server_id + if mail_server and not mail_server._match_from_filter(mailing.email_from, mail_server.from_filter): + mailing.warning_message = _( + 'This email from can not be used with this mail server.\n' + 'Your emails might be marked as spam on the mail clients.' + ) + else: + mailing.warning_message = False + @api.depends('mailing_type') def _compute_medium_id(self): for mailing in self: diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml index 5b9c3405fea..6178fb2d452 100644 --- a/addons/mass_mailing/views/mailing_mailing_views.xml +++ b/addons/mass_mailing/views/mailing_mailing_views.xml @@ -65,7 +65,8 @@ -