Skip to content

Commit f10a817

Browse files
authored
Catch bad "To:" in mails (#748)
I don't like receiving every other day a monstruosity like: > [see the PR description for example content] Instead of an infinitely clearer straight-to-the-point one-liner that wouldn't mess around with our logs monitoring: >uvicorn.error - ERROR - Bad email adress: "". For mail with subject "MyECL - reset your password".
1 parent 69636d1 commit f10a817

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/utils/mail/mailworker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ def send_email(
4040
with smtplib.SMTP(settings.SMTP_SERVER, settings.SMTP_PORT) as server:
4141
server.starttls(context=context)
4242
server.login(settings.SMTP_USERNAME, settings.SMTP_PASSWORD)
43-
server.send_message(msg, settings.SMTP_EMAIL, recipient)
43+
try:
44+
server.send_message(msg, settings.SMTP_EMAIL, recipient)
45+
except smtplib.SMTPRecipientsRefused:
46+
hyperion_error_logger.warning(
47+
f'Bad email adress: "{", ".join(recipient)}" for mail with subject "{subject}".',
48+
)

0 commit comments

Comments
 (0)