[FIX] mail: do not try to send email to partners without email

As `formataddr` only accept strings as arguments, an exception was
raised when trying to notify a mailing list channel with followers
without email.

closes odoo/odoo#30492
This commit is contained in:
Christophe Simonis
2019-01-23 19:22:00 +00:00
parent 9254216843
commit b42cd64ace
2 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -352,7 +352,7 @@ class Channel(models.Model):
# real mailing list: multiple recipients (hidden by X-Forge-To)
if self.alias_domain and self.alias_name:
return {
'email_to': ','.join(formataddr((partner.name, partner.email)) for partner in whitelist),
'email_to': ','.join(formataddr((partner.name, partner.email)) for partner in whitelist if partner.email),
'recipient_ids': [],
}
return super(Channel, self)._notify_email_recipients(message, whitelist.ids)
+9 -1
View File
@@ -155,7 +155,15 @@ class TestChannelFeatures(common.BaseFunctionalTest, common.MockEmails):
""" Posting a message on a mailing list should send one email to all recipients """
self.env['ir.config_parameter'].set_param('mail.catchall.domain', 'schlouby.fr')
self.test_channel.write({'email_send': True})
self._join_channel(self.test_channel, self.user_employee.partner_id | self.test_partner)
# Subscribe an user without email. We shouldn't try to send email to them.
nomail = self.env['res.users'].create({
"login": "nomail",
"name": "No Mail",
"email": False,
"notification_type": "email",
})
self._join_channel(self.test_channel, self.user_employee.partner_id | self.test_partner | nomail.partner_id)
self.test_channel.message_post(body="Test", message_type='comment', subtype='mt_comment')
self.assertEqual(len(self._mails), 1)