Skip to content

Commit

Permalink
added more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
riley206 committed Aug 20, 2024
1 parent 87650e1 commit 5e36e90
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions services/ops/EmailerAgent/emailer/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# Import the email modules we'll need
from email.mime.text import MIMEText
from smtplib import SMTPException
import logging
import socket

Expand Down Expand Up @@ -251,17 +252,27 @@ def _send_email(self, from_address, to_addresses, mime_message):
self.vip.health.set_status(STATUS_GOOD,
"Successfully sent email.")
send_successful = True
except SMTPException as smtp_err:
_log.error(f"SMTP error occurred: {smtp_err}")
_log.error(f"Unable to send email message: {mime_message.as_string()}")
self.vip.health.set_status(
STATUS_BAD,
"SMTP configuration or authentication issue. Please check your SMTP settings and credentials.")

except OSError as os_err:
_log.error(f"Network-related error occurred: {os_err}")
_log.error(f"Unable to send email message: {mime_message.as_string()}")
self.vip.health.set_status(
STATUS_BAD, "Network issue. Please check your internet connection and SMTP server accessibility.")

except Exception as e:
_log.error(
'Unable to send email message: %s' % mime_message.as_string())
_log.error(e.args)
self.vip.health.set_status(STATUS_BAD,
"Unable to send email to recipients")
_log.error(f"An unexpected error occurred: {e}")
_log.error(f"Unable to send email message: {mime_message.as_string()}")
self.vip.health.set_status(STATUS_BAD, f"Unable to send email to recipients: {e}")
finally:
if sent_email_record is not None:
sent_email_record['successful'] = send_successful
self.vip.pubsub.publish("pubsub", "record/sent_email",
message=sent_email_record)
self.vip.pubsub.publish("pubsub", "record/sent_email", message=sent_email_record)

def send_email(self, from_address, to_addresses, subject, message):
"""
Expand Down

0 comments on commit 5e36e90

Please sign in to comment.