Skip to content

Commit

Permalink
feat: add email error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
trowik authored and anehx committed Jan 6, 2023
1 parent a4e8997 commit 012a893
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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.
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)

0 comments on commit 012a893

Please sign in to comment.