From a9c27a2c7e7b8d1d82e59258156c3ad8bb0f3e15 Mon Sep 17 00:00:00 2001 From: Tom Blauwendraat Date: Thu, 6 Apr 2023 22:33:19 +0200 Subject: [PATCH] [FIX] backport _smtp_login as well --- odoo/addons/base/ir/ir_mail_server.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/ir/ir_mail_server.py b/odoo/addons/base/ir/ir_mail_server.py index 3f839a38fd5a3..eff8890f32f6a 100644 --- a/odoo/addons/base/ir/ir_mail_server.py +++ b/odoo/addons/base/ir/ir_mail_server.py @@ -191,6 +191,9 @@ def connect(self, host=None, port=None, user=None, password=None, encryption=Non elif not host: mail_server = self.sudo().search([], order='sequence', limit=1) + if not mail_server: + mail_server = self.env['ir.mail_server'] + if mail_server: smtp_server = mail_server.smtp_host smtp_port = mail_server.smtp_port @@ -241,9 +244,19 @@ def connect(self, host=None, port=None, user=None, password=None, encryption=Non # See also bug #597143 and python issue #5285 smtp_user = pycompat.to_native(ustr(smtp_user)) smtp_password = pycompat.to_native(ustr(smtp_password)) - connection.login(smtp_user, smtp_password) + mail_server._smtp_login(connection, smtp_user, smtp_password) return connection + def _smtp_login(self, connection, smtp_user, smtp_password): + """Authenticate the SMTP connection. + Can be overridden in other module for different authentication methods.Can be + called on the model itself or on a singleton. + :param connection: The SMTP connection to authenticate + :param smtp_user: The user to used for the authentication + :param smtp_password: The password to used for the authentication + """ + connection.login(smtp_user, smtp_password) + 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'):