def reconnect(self):
auth_attempts = 0
while auth_attempts <= constants.MAX_RECONNECT_RETRIES:
auth_attempts += 1
try:
self.mail = imaplib.IMAP4_SSL(pub_config['gmail']['imap'])
u, data = self.mail.login(private_config['gmail']['username'],
private_config['gmail']['password'])
return
except imaplib.IMAP4.error as e:
logging.error("Login to retrieve emails failed!")
logging.error(e)
except Exception as e:
logging.error("Error from IMAP! Trying to reconnect...")
logging.error(e)
time.sleep(constants.SMTP_RECONNECT_SLEEP_TIME)
if auth_attempts > constants.MAX_RECONNECT_RETRIES:
from pnu.outbound.alerter import smtp
logging.critical("Could not connect to IMAP handler")
smtp.send_error("Could not connect to IMAP handler")
评论列表
文章目录