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

Add incident for SMTP errors #5704

Closed
wants to merge 1 commit into from
Closed

Add incident for SMTP errors #5704

wants to merge 1 commit into from

Conversation

norkans7
Copy link

No description provided.


def send(self, recipients: list, subject: str, template: str, context: dict):
"""
Sends a multi-part email rendered from templates for the text and html parts. `template` should be the name of
the template, without .html or .txt (e.g. 'channels/email/power_charging').
"""
from temba.notifications.incidents.builtin import OrgSMTPFailedIncidentType
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid circular imports

send_email(recipients, subject, text, html, self.from_email, self.connection)
try:
send_email(recipients, subject, text, html, self.from_email, self.connection)
except smtplib.SMTPException:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extended to catch all SMTPException not just SMTPAuthenticationError

Comment on lines +71 to +79
OrgSMTPFailedIncidentType.get_or_create(self.org)
return
except Exception as e:
raise e
OrgSMTPFailedIncidentType.find_and_end(self.org)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this here to avoid the repetition everywhere we send emails

self.branding = branding
self.connection = connection # can be none to use default Django email connection
self.from_email = from_email if from_email else getattr(settings, "DEFAULT_FROM_EMAIL", "[email protected]")
self.org = org
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added org so we can make the incident for the correct org, however we do not have org all them time such as the case for user forget password view, in that case we cannot create an incident.

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (950a7df) to head (44b21fb).
Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #5704    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          572       573     +1     
  Lines        25925     26383   +458     
==========================================
+ Hits         25925     26383   +458     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rowanseymour rowanseymour deleted the smtp-failed branch November 27, 2024 18:55
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants