diff --git a/src/ns/adapters/outbound/smtp_client.py b/src/ns/adapters/outbound/smtp_client.py index 79912ff..8f523bb 100644 --- a/src/ns/adapters/outbound/smtp_client.py +++ b/src/ns/adapters/outbound/smtp_client.py @@ -75,11 +75,13 @@ def get_connection(self) -> Generator[SMTP, None, None]: ) try: + log.debug("Attempting to establish SMTP connection (timeout=%s).", timeout) with ( SMTP(self._config.smtp_host, self._config.smtp_port, timeout=timeout) if timeout else SMTP(self._config.smtp_host, self._config.smtp_port) as server ): + log.debug("STMP connection successfully established.") yield server except OSError as err: # TimeoutError is a subclass of OSError, but a blocked port can result @@ -105,6 +107,7 @@ def send_email_message(self, message: EmailMessage): username = self._config.smtp_auth.username password = self._config.smtp_auth.password.get_secret_value() try: + log.debug("Authenticating against the SMTP server.") server.login(username, password) except SMTPAuthenticationError as err: login_error = self.FailedLoginError() @@ -112,12 +115,15 @@ def send_email_message(self, message: EmailMessage): raise login_error from err # check for a connection + log.debug("Performing NOOP to verify SMTP connection.") if server.noop()[0] != 250: connection_error = self.ServerPingError() log.critical(connection_error) raise connection_error + log.debug("NOOP successful, sending email.") server.send_message(msg=message) + log.debug("Email sent.") except SMTPException as exc: error = self.GeneralSmtpException(error_info=exc.args[0]) log.error(error, extra={"error_info": exc.args[0]}) diff --git a/src/ns/core/notifier.py b/src/ns/core/notifier.py index 2cddc0a..1bcf4e2 100644 --- a/src/ns/core/notifier.py +++ b/src/ns/core/notifier.py @@ -115,6 +115,7 @@ async def send_notification(self, *, notification: event_schemas.Notification): await self._register_new_notification(notification_record=notification_record) message = self._construct_email(notification=notification) + log.info("Sending notification") self._smtp_client.send_email_message(message) # update the notification record to show that the notification has been sent.