diff --git a/lnbits/core/services/notifications.py b/lnbits/core/services/notifications.py index 8860fbd6a..fba38b42f 100644 --- a/lnbits/core/services/notifications.py +++ b/lnbits/core/services/notifications.py @@ -222,12 +222,20 @@ async def send_email( msg["Subject"] = subject msg.attach(MIMEText(message, "plain")) username = username if len(username) > 0 else from_email - with smtplib.SMTP(server, port) as smtp_server: - smtp_server.starttls() - smtp_server.login(username, password) - smtp_server.sendmail(from_email, to_emails, msg.as_string()) + + def _send() -> bool: + with smtplib.SMTP(server, port) as smtp_server: + smtp_server.starttls() + smtp_server.login(username, password) + smtp_server.sendmail(from_email, to_emails, msg.as_string()) return True + try: + return await asyncio.to_thread(_send) + except Exception as e: + logger.warning(f"Sending Email failed. {e!s}") + return False + async def dispatch_webhook(payment: Payment): """