コード例 #1
0
ファイル: test_extension.py プロジェクト: vitalk/flask-mailer
def test_extension_use_the_application_bound_to_the_current_context(app, mail):
    mailer = Mailer()
    mailer.init_app(app)

    with app.test_request_context():
        mailer.send(mail)
        assert mailer.outbox == [mail,]
コード例 #2
0
ファイル: test_extension.py プロジェクト: vitalk/flask-mailer
def test_extension_raises_error_if_no_application_bound_to_context(app, mail):
    mailer = Mailer()
    mailer.init_app(app)

    with pytest.raises(RuntimeError) as exc:
        mailer.send(mail)
        assert 'no application bound to current context' in exc.exconly()
コード例 #3
0
ファイル: test_extension.py プロジェクト: vitalk/flask-mailer
def test_extension_raises_error_if_not_properly_initialized(app, mail):
    mailer = Mailer()
    err = 'Mailer extension does not registered ' \
          'with current application or' \
          'no application bound to current context'

    with pytest.raises(RuntimeError) as exc:
        mailer.send(mail)
        assert err in exc.exconly()

    with app.test_request_context():
        with pytest.raises(RuntimeError) as exc:
            mailer.send(mail)
            assert err in exc.exconly()
コード例 #4
0
ファイル: __init__.py プロジェクト: allesrebel/flask_learning
db = SQLAlchemy(app)

from flask_migrate import Migrate

migrate = Migrate(app, db)

from flask_login import LoginManager

login = LoginManager(app)
# Configure Login Manager to force login for protected pages
login.login_view = 'login'

from flask_mailer import Mailer

smtp = Mailer(app)

from flask_bootstrap import Bootstrap

bootstrap = Bootstrap(app)

if not app.debug:
    if app.config['MAIL_SERVER']:
        auth = None
        if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
            auth = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD'])
        secure = None
        if app.config['MAIL_USE_TLS']:
            secure = ()
        mail_handler = SMTPHandler(
            mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
コード例 #5
0
from flask import Flask
from flask_mailer import Mailer, Email

app = Flask(__name__)
smtp = Mailer(app)

mail = Email(subject='hi, there',
             text='awesome message',
             to=['*****@*****.**'],
             from_addr='*****@*****.**')
smtp.send(mail)