26 lines
747 B
Python
26 lines
747 B
Python
|
from flask import Flask
|
||
|
from flask_mail import Mail, Message
|
||
|
|
||
|
from app import app
|
||
|
from util.config.validators import BaseValidator
|
||
|
|
||
|
class EmailValidator(BaseValidator):
|
||
|
name = "mail"
|
||
|
|
||
|
@classmethod
|
||
|
def validate(cls, config, user, user_password):
|
||
|
""" Validates sending email. """
|
||
|
with app.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" % app.config['REGISTRY_TITLE'],
|
||
|
sender=config.get('MAIL_DEFAULT_SENDER'))
|
||
|
test_msg.add_recipient(user.email)
|
||
|
test_mail.send(test_msg)
|