import logging from threading import Thread # Configure logging at the beginning of your application # logging.basicConfig(level=logging.INFO, filename='app.log', filemode='a', format='%(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) def send_email_async(email_service): try: email_service.send() print("Email sent from utils successfully!") except Exception as e: # Log the exception print(f"Failed to send email: {e}") logger.error(f"Failed to send email: {e}") # Optionally, you could use other means to notify you of the failure, # such as sending an alert to an admin email, or using a monitoring service.