diff --git a/compendium_v2/__init__.py b/compendium_v2/__init__.py index 9d1b68d063ca54b1cce4e0b32e44e324a2cf2452..187920aca1d14c2aed83879055f3c13458588344 100644 --- a/compendium_v2/__init__.py +++ b/compendium_v2/__init__.py @@ -67,6 +67,17 @@ def _create_app_with_db(app_config) -> Flask: # for the publishers app.config['SQLALCHEMY_BINDS'] = app_config['SQLALCHEMY_BINDS'] + if 'mail' in app_config: + mail_config = app_config['mail'] + app.config['MAIL_ENABLE'] = True + app.config['MAIL_SERVER'] = mail_config['MAIL_SERVER'] + app.config['MAIL_PORT'] = mail_config['MAIL_PORT'] + app.config['MAIL_SENDER_EMAIL'] = mail_config['MAIL_SENDER_EMAIL'] # email address to send emails from + excluded_admins = mail_config.get('MAIL_EXCLUDED_ADMINS', []) + app.config['MAIL_EXCLUDED_ADMINS'] = excluded_admins # list of admin emails not to send emails to + else: + app.config['MAIL_ENABLE'] = False + db.init_app(app) return app diff --git a/compendium_v2/config.py b/compendium_v2/config.py index 490f399a55af8bff0a2d0b82e45ef6ae2fbbd6fa..4c67ad9842da0bd6b930f934d52898efb4377cc8 100644 --- a/compendium_v2/config.py +++ b/compendium_v2/config.py @@ -17,6 +17,20 @@ CONFIG_SCHEMA = { 'required': ['client_id', 'client_secret', 'server_metadata_url'], 'additionalProperties': False }, + 'mail': { + 'type': 'object', + 'properties': { + 'MAIL_SERVER': {'type': 'string'}, + 'MAIL_PORT': {'type': 'integer'}, + 'MAIL_SENDER_EMAIL': {'type': 'string', 'format': 'email'}, + 'MAIL_EXCLUDED_ADMINS': { + 'type': 'array', + 'items': {'type': 'string', 'format': 'email'} + } + }, + 'required': ['MAIL_SERVER', 'MAIL_PORT', 'MAIL_SENDER_EMAIL'], + 'additionalProperties': False + }, 'SECRET_KEY': {'type': 'string'}, }, 'required': ['SQLALCHEMY_DATABASE_URI', 'SURVEY_DATABASE_URI', 'SECRET_KEY'],