Skip to content

Commit 7688a0e

Browse files
committed
continue email scheduling after google server crash
1 parent 7b844b5 commit 7688a0e

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

core/utils.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import asyncio
22
import smtplib
3+
import traceback
34
from contextlib import asynccontextmanager
4-
from datetime import date, datetime, time as dt_time, timedelta
5+
from datetime import date, datetime
6+
from datetime import time as dt_time
7+
from datetime import timedelta
58
from email.message import EmailMessage
69
from email.mime.text import MIMEText
710
from functools import wraps
@@ -265,10 +268,14 @@ async def handle_daily_emails(app):
265268
messages.append(msg)
266269

267270
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
268-
smtp.login(app.config.NOREPLY_EMAIL, app.config.EMAIL_APP_PASSWORD)
269-
270-
for msg in messages:
271-
smtp.send_message(msg)
271+
try:
272+
smtp.login(app.config.NOREPLY_EMAIL, app.config.EMAIL_APP_PASSWORD)
273+
except smtplib.SMTPAuthenticationError:
274+
# Prevent failure of email scheduling if Google's servers crash (like on 12/14/20)
275+
print(traceback.format_exc())
276+
else:
277+
for msg in messages:
278+
smtp.send_message(msg)
272279

273280
# Prevent it from sending twice
274281
await asyncio.sleep(1)

0 commit comments

Comments
 (0)