Unable to log Flask exceptions with SMTP handler <p>I am attempting to get an email sent to me any time an error occurs in my Flask application. The email is not being sent despite the handler being registered. I used <code>smtplib</code> to verify that my SMTP login details are correct. The error is displayed in Werkzeug's debugger, but no emails are sent. How do I log exceptions that occur in my app?</p> <pre><code>import logging from logging.handlers import SMTPHandler from flask import Flask app = Flask(__name__) app.debug = True app.config['PROPAGATE_EXCEPTIONS'] = True if app.debug: logging.basicConfig(level=logging.INFO) # all of the $ names have actual values handler = SMTPHandler( mailhost = 'smtp.mailgun.org', fromaddr = 'Application Bug Reporter &lt;$mailgun_email_here&gt;', toaddrs = ['$personal_email_here'], subject = 'Test Application Logging Email', credentials = ('$mailgun_email_here', '$mailgun_password_here') ) handler.setLevel(logging.ERROR) app.logger.addHandler(handler) @app.route('/') def index(): raise Exception('Hello, World!') # should trigger an email app.run() </code></pre>