From c10899167a8e535223e655ffc1a0feb44fd3066b Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 20 Sep 2019 07:44:55 +0000 Subject: [PATCH] [FIX] l10n_it_edi: sent certified email without reply-to or return-path Before this commit, when the domain alias was set (e.g. my_domain.com), the reply-to and the reply-path were filled with default values using this domain (e.g. reply-to : catchall@my_domain.com and reply-path: Return-Path: bounce+number@my_domain.com). As we have a second SMTP server, the certified email (https://en.wikipedia.org/wiki/Certified_email), with a different domain than the domain alias filled in the settings, the SMTP servers will arise an error : "SMTPRecipientsRefused: Sender address rejected: not owned by user", this error arise because the domain of the certified email is different from the one setted in the settings, is also different from the domains of the reply-to and the return-path. Now, when we know that we are going to use the certified email SMTP server, for example to send invoices to the Italian government, the email will be sent without a reply-to or without a reply-path. This behaviour is exactly the same as the behaviour will have if we didn't set a domain alias. opw-2045244 X-original-commit: 66c5053 --- addons/l10n_it_edi/models/account_invoice.py | 3 ++- addons/l10n_it_edi/models/ir_mail_server.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/l10n_it_edi/models/account_invoice.py b/addons/l10n_it_edi/models/account_invoice.py index c78a295a008..a5fea8e86cb 100644 --- a/addons/l10n_it_edi/models/account_invoice.py +++ b/addons/l10n_it_edi/models/account_invoice.py @@ -273,11 +273,12 @@ class AccountInvoice(models.Model): 'subject': _('Sending file: %s') % (self.l10n_it_einvoice_id.name), 'body': _('Sending file: %s to ES: %s') % (self.l10n_it_einvoice_id.name, self.env.user.company_id.l10n_it_address_recipient_fatturapa), 'email_from': self.env.user.company_id.l10n_it_address_send_fatturapa, + 'reply_to': self.env.user.company_id.l10n_it_address_send_fatturapa, 'mail_server_id': self.env.user.company_id.l10n_it_mail_pec_server_id.id, 'attachment_ids': [(6, 0, self.l10n_it_einvoice_id.ids)], }) - mail_fattura = self.env['mail.mail'].create({ + mail_fattura = self.env['mail.mail'].with_context(wo_return_path=True).create({ 'mail_message_id': message.id, 'email_to': self.env.user.company_id.l10n_it_address_recipient_fatturapa, }) diff --git a/addons/l10n_it_edi/models/ir_mail_server.py b/addons/l10n_it_edi/models/ir_mail_server.py index 095dd293d8b..6e0b45d3bcf 100644 --- a/addons/l10n_it_edi/models/ir_mail_server.py +++ b/addons/l10n_it_edi/models/ir_mail_server.py @@ -356,3 +356,17 @@ class FetchmailServer(models.Model): if descrizione: output_str += "
  • Errore %s: %s
  • " % (element[0].text, descrizione) return output_str + "" + +class IrMailServer(models.Model): + _name = "ir.mail_server" + _inherit = "ir.mail_server" + + def build_email(self, email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False, + attachments=None, message_id=None, references=None, object_id=False, subtype='plain', headers=None, + body_alternative=None, subtype_alternative='plain'): + + if self.env.context.get('wo_return_path') and headers: + headers.pop('Return-Path', False) + return super(IrMailServer, self).build_email(email_from, email_to, subject, body, email_cc, email_bcc, reply_to, + attachments, message_id, references, object_id, subtype, headers, + body_alternative, subtype_alternative)