diff options
Diffstat (limited to 'addons/mass_mailing/models/mail_thread.py')
| -rw-r--r-- | addons/mass_mailing/models/mail_thread.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/addons/mass_mailing/models/mail_thread.py b/addons/mass_mailing/models/mail_thread.py index 4d17c5321c6..85d42827617 100644 --- a/addons/mass_mailing/models/mail_thread.py +++ b/addons/mass_mailing/models/mail_thread.py @@ -3,11 +3,13 @@ import logging import re +import datetime -from odoo import api, models, tools +from odoo import api, models, tools, fields from odoo.tools import decode_smtp_header, decode_message_header _logger = logging.getLogger(__name__) +BLACKLIST_MAX_BOUNCED_LIMIT = 5 class MailThread(models.AbstractModel): @@ -49,4 +51,26 @@ class MailThread(models.AbstractModel): default_mass_mailing_name=False, default_mass_mailing_id=False, ) - return super(MailThread, no_massmail).message_post_with_template(template_id, **kwargs)
\ No newline at end of file + return super(MailThread, no_massmail).message_post_with_template(template_id, **kwargs) + + @api.multi + def message_receive_bounce(self, email, partner, mail_id=None): + """In addition, an auto blacklist rule check if the email can be blacklisted + to avoid sending mails indefinitely to this email address. + This rule checks if the email bounced too much. If this is the case, + the email address is added to the blacklist in order to avoid continuing + to send mass_mail to that email address. If it bounced too much times + in the last month and the bounced are at least separated by one week, + to avoid blacklist someone because of a temporary mail server error, + then the email is considered as invalid and is blacklisted.""" + super(MailThread, self).message_receive_bounce(email, partner, mail_id=None) + + three_months_ago = fields.Datetime.to_string(datetime.datetime.now() - datetime.timedelta(weeks=13)) + stats = self.env['mail.mail.statistics'] \ + .search(['&', ('bounced', '>', three_months_ago), ('email', '=ilike', email)]) \ + .mapped('bounced') + if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT: + if max(stats) > min(stats) + datetime.timedelta(weeks=1): + blacklist_rec = self.env['mail.blacklist'].sudo()._add(email) + blacklist_rec._message_log( + 'This email has been automatically blacklisted because of too much bounced.') |
