diff --git a/frappe/email/receive.py b/frappe/email/receive.py index e624d82a10..5907528f38 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -162,10 +162,14 @@ class EmailServer: return res[0] == "OK" # The folder exists TODO: handle other responses too def logout(self): - if cint(self.settings.use_imap): - self.imap.logout() - else: - self.pop.quit() + try: + if cint(self.settings.use_imap): + self.imap.logout() + else: + self.pop.quit() + except imaplib.IMAP4.abort: + self.connect() + self.logout() return def get_messages(self, folder="INBOX"):