diff --git a/frappe/email/oauth.py b/frappe/email/oauth.py index 740aefc6a6..c432bcf45a 100644 --- a/frappe/email/oauth.py +++ b/frappe/email/oauth.py @@ -32,14 +32,21 @@ class Oauth: self._access_token = access_token self._refresh_token = refresh_token - self.validate_implementation() + self.validate() - def validate_implementation(self) -> None: + def validate(self) -> None: if self.service != "GMail": raise NotImplementedError( f"Service {self.service} currently doesn't have oauth implementation." ) + if not self._refresh_token: + frappe.throw( + frappe._("Please Authorize OAuth."), + OAuthenticationError, + frappe._("OAuth Error"), + ) + @property def _auth_string(self) -> str: return "user=%s\1auth=Bearer %s\1\1" % (self.email, self._access_token) diff --git a/frappe/email/receive.py b/frappe/email/receive.py index 8bfd177579..e26748dd07 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -100,7 +100,7 @@ class EmailServer: self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout") ) - if self.settings.use_oauth and self.settings.refresh_token: + if self.settings.use_oauth: Oauth( self.imap, self.settings.email_account, @@ -133,7 +133,7 @@ class EmailServer: self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout") ) - if self.settings.use_oauth and self.settings.refresh_token: + if self.settings.use_oauth: Oauth( self.pop, self.settings.email_account, diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py index f5e2af7194..687b8318b6 100644 --- a/frappe/email/smtp.py +++ b/frappe/email/smtp.py @@ -111,7 +111,7 @@ class SMTPServer: self.secure_session(_session) - if self.use_oauth and self.refresh_token: + if self.use_oauth: Oauth( _session, self.email_account, self.login, self.access_token, self.refresh_token, self.service ).connect()