diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 717d37c0500..feea6292e8f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -798,15 +798,20 @@ class MailThread(models.AbstractModel): record_set = None def _create_bounce_email(): - self.env['mail.mail'].create({ + bounce_to = decode_header(message, 'Return-Path') or email_from + bounce_mail_values = { 'body_html': '
Hello,
' 'The following email sent to %s cannot be accepted because this is ' 'a private email address. Only allowed people can contact us at this address.
%s' % (message.get('to'), message_dict.get('body')), 'subject': 'Re: %s' % message.get('subject'), - 'email_to': message.get('from'), + 'email_to': bounce_to, 'auto_delete': True, - }).send() + } + bounce_from = self.env['ir.mail_server']._get_default_bounce_address() + if bounce_from: + bounce_mail_values['email_from'] = 'MAILER-DAEMON <%s>' % bounce_from + self.env['mail.mail'].create(bounce_mail_values).send() def _warn(message): _logger.info('Routing mail with Message-Id %s: route %s: %s', diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 11b9bb3b9a7..9c1bc2216da 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -313,8 +313,8 @@ class TestMailgateway(TestMail): 'message_process: incoming email on Partners alias should send a bounce email') self.assertIn('New Frogs', self._mails[0].get('subject'), 'message_process: bounce email on Partners alias should contain the original subject') - self.assertIn(formataddr(('Sylvie Lelitre', 'test.sylvie.lelitre@agrolait.com')), self._mails[0].get('email_to'), - 'message_process: bounce email on Partners alias should have original email sender as recipient') + self.assertIn('whatever-2a840@postmaster.twitter.com', self._mails[0].get('email_to'), + 'message_process: bounce email on Partners alias should go to Return-Path address') @mute_logger('openerp.addons.mail.models.mail_thread', 'openerp.models', 'openerp.addons.mail.models.mail_mail') def test_message_process_alias_followers_bounce(self):