[FIX] mail: stop spamming CCs of outgoing emails

Fix usage of CCs when sending emails. Currently CCs are added to all outgoing
emails, which leads to unnecessary spam. Recipients are currently computed like

  * create an outgoing email based on 'email_to';
  * create one outgoing email / partner in 'recipient_ids';
  * add CCs to all outgoing emails;

They are now sent only once, either with the email_to if given, either as
standalone. That way partners receive specific emails (due to tracking and
partner specific links management), email_to / email_cc are sent on their own.

Task-3093268 (Mail: Stop spamming CCs)
Prepares Task-2684479 (Mail: Better report errors when sending emails)

Part-of: odoo/odoo#99482
This commit is contained in:
Thibault Delavallée
2023-01-17 20:58:33 +01:00
parent 91672b1cab
commit d6aa0050da
2 changed files with 17 additions and 5 deletions
+14 -3
View File
@@ -373,19 +373,30 @@ class MailMail(models.Model):
if self.email_to:
email_to = tools.email_split_and_format(self.email_to)
email_list.append({
'email_cc': [],
'email_to': email_to,
# keep raw initial value for incoming pre processing of outgoing emails
'email_to_raw': self.email_to or '',
'partner_id': False,
})
# TODO: add all cc once, either to the "To", either as a single entry (do not mix
# add all cc once, either to the first "To", either as a single entry (do not mix
# with partner-specific sending)
email_cc = tools.email_split(self.email_cc)
if self.email_cc:
if email_list:
email_list[0]['email_cc'] = tools.email_split(self.email_cc)
else:
email_list.append({
'email_cc': tools.email_split(self.email_cc),
'email_to': [],
'email_to_raw': False,
'partner_id': False,
})
# specific behavior to customize the send email for notified partners
for partner in self.recipient_ids:
# check partner email content
email_to = [tools.formataddr((partner.name or '', partner.email or 'False'))]
email_list.append({
'email_cc': [],
'email_to': email_to,
# keep raw initial value for incoming pre processing of outgoing emails
'email_to_raw': partner.email or '',
@@ -415,7 +426,7 @@ class MailMail(models.Model):
'attachments': email_attachments,
'body': body,
'body_alternative': body_alternative,
'email_cc': email_cc,
'email_cc': email_values['email_cc'],
'email_from': self.email_from,
'email_to': email_values['email_to'],
'email_to_raw': email_values['email_to_raw'],
+3 -2
View File
@@ -195,9 +195,10 @@ class TestMailMail(TestMailCommon):
self.assertSentEmail(mail.env.user.partner_id,
['test.rec.1@example.com', '"Raoul" <test.rec.2@example.com>'],
email_cc=['test.cc.1@example.com', 'test.cc.2@example.com'])
# Mail: currently cc are put as copy of all sent emails (aka spam)
# don't put CCs as copy of each outgoing email, only the first one (and never
# with partner based recipients as those may receive specific links)
self.assertSentEmail(mail.env.user.partner_id, [self.user_employee.email_formatted],
email_cc=['test.cc.1@example.com', 'test.cc.2@example.com'])
email_cc=[])
self.assertEqual(len(self._mails), 2)
@mute_logger('odoo.addons.mail.models.mail_mail')