Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added more logging #3189

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading