From a9c27a2c7e7b8d1d82e59258156c3ad8bb0f3e15 Mon Sep 17 00:00:00 2001 From: Tom Blauwendraat Date: Thu, 6 Apr 2023 22:33:19 +0200 Subject: [PATCH 1/2] [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 3f839a38fd5a3b..eff8890f32f6a9 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'): From 3622b081670d18edad6bac9cc93b7e719c7081c7 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Thu, 14 Sep 2023 00:13:26 +0300 Subject: [PATCH 2/2] [11.0][IMP] 3292S Microsoft SMTP token refresh issue --- addons/microsoft_outlook/models/microsoft_outlook_mixin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/microsoft_outlook/models/microsoft_outlook_mixin.py b/addons/microsoft_outlook/models/microsoft_outlook_mixin.py index 3facadf0e26321..37bf28cb412e71 100644 --- a/addons/microsoft_outlook/models/microsoft_outlook_mixin.py +++ b/addons/microsoft_outlook/models/microsoft_outlook_mixin.py @@ -110,6 +110,7 @@ def _fetch_outlook_access_token(self, refresh_token): """ response = self._fetch_outlook_token('refresh_token', refresh_token=refresh_token) return ( + response['refresh_token'], response['access_token'], int(time.time()) + response['expires_in'], ) @@ -164,6 +165,7 @@ def _generate_outlook_oauth2_string(self, login): if not self.microsoft_outlook_refresh_token: raise UserError(_('Please login your Outlook mail server before using it.')) ( + self.microsoft_outlook_refresh_token, self.microsoft_outlook_access_token, self.microsoft_outlook_access_token_expiration, ) = self._fetch_outlook_access_token(self.microsoft_outlook_refresh_token)