Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] backport _smtp_login as well #3

Open
wants to merge 2 commits into
base: 11.0-microsoft-outlook-2022-std
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/microsoft_outlook/models/microsoft_outlook_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion odoo/addons/base/ir/ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down