def test_mail_handler(self):
        from . import FlaskMailHandler
        from ..ext import mail

        mail.username = 'test@test.com'
        mail.password = 'test'
        self.app.config['ADMINS'] = ['test@test.com']
        self.app.config['DEFAULT_MAIL_SENDER'] = 'test@test.com'
        self.app.logger.addHandler(FlaskMailHandler(40))
        propagate_exceptions = self.app.config.get('PROPAGATE_EXCEPTIONS')
        self.app.config['PROPAGATE_EXCEPTIONS'] = False

        @self.app.route('/error')
        def error():
            raise Exception('Error content')
        assert error

        with mail.record_messages() as outbox:
            self.app.logger.error('Attention!')
            self.assertTrue(outbox)
            msg = outbox.pop()
            self.assertEqual(msg.subject, 'APP ERROR: http://localhost/')

            self.client.get('/error')
            msg = outbox.pop()
            self.assertTrue('Error content', )

        self.app.config['PROPAGATE_EXCEPTIONS'] = propagate_exceptions
Handle errors by mail.
dataset/ETHPy150Open klen/Flask-Foundation/base/core/tests.py/CoreTest.test_mail_handler