from flask import Flask from flask_mail import Mail, Message from util.config.validators import BaseValidator class EmailValidator(BaseValidator): name = "mail" @classmethod def validate(cls, validator_context): """ Validates sending email. """ config = validator_context.config user = validator_context.user app_context = validator_context.context registry_title = validator_context.registry_title with app_context(): test_app = Flask("mail-test-app") test_app.config.update(config) test_app.config.update({ 'MAIL_FAIL_SILENTLY': False, 'TESTING': False }) test_mail = Mail(test_app) test_msg = Message("Test e-mail from %s" % registry_title, sender=config.get('MAIL_DEFAULT_SENDER')) test_msg.add_recipient(user.email) test_mail.send(test_msg)