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

feat: add email error handler #575

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ Users of nginx/apache must ensure to have matching CORS configurations.
* `PAGINATION_ENABLED`: whether the pagination is enabled (default: `True`)
* `PAGINATION_DEFAULT_PAGE_SIZE`: the default page size if no query param (`page_size`) is given (default: `100`)
* `PAGINATION_MAX_PAGE_SIZE`: the max value of the page size query param (`page_size`) (default: `1000`)

## Email error handler
* `ENABLE_ADMIN_EMAIL_LOGGING`: enable Django to send email to admins on errors (default: `False`)
* `SERVER_MAIL`: the email address that error messages come from
* `EMAIL_HOST`: the host to use for sending email (default: `localhost`)
* `EMAIL_PORT`: port to use for the SMTP server (default: `25`)
* `EMAIL_HOST_USER`: username for the SMTP server(default: "")
* `EMAIL_HOST_PASSWORD`: password for the SMTP server user (default: "")
* `EMAIL_USE_TLS`: whether to use an implicit TLS (secure) connection when talking to the SMTP server (default: `False`)
* `ADMINS`: list of people who will get code error notifications. Items in the list should follow this example: `Test Example <[email protected]>,Test2 <[email protected]>`

If either `EMAIL_HOST_USER` or `EMAIL_HOST_PASSWORD` is empty, Django won't attempt authentication.
anehx marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 18 additions & 1 deletion document_merge_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def parse_admins(admins):
)

# Logging
ENABLE_ADMIN_EMAIL_LOGGING = env.bool("ENABLE_ADMIN_EMAIL_LOGGING", False)

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
Expand All @@ -235,9 +237,24 @@ def parse_admins(admins):
"level": "WARNING",
"filters": None,
"class": "logging.StreamHandler",
}
},
"mail_admins": {
"level": "ERROR",
"filters": None,
"class": "django.utils.log.AdminEmailHandler",
},
},
"loggers": {"django": {"handlers": ["console"], "level": "WARNING"}},
}

URL_PREFIX = env.str("URL_PREFIX", default="")

# Email settings
if ENABLE_ADMIN_EMAIL_LOGGING: # pragma: no cover
LOGGING["loggers"]["django"]["handlers"].append("mail_admins") # type: ignore
SERVER_MAIL = env.str("SERVER_MAIL", default="root@localhost")
EMAIL_HOST = env.str("EMAIL_HOST", default="localhost")
EMAIL_PORT = env.int("EMAIL_PORT", default=25)
EMAIL_HOST_USER = env.str("EMAIL_HOST_USER", default="")
EMAIL_HOST_PASSWORD = env.str("EMAIL_HOST_PASSWORD", default="")
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", default=False)