Last active
August 31, 2015 02:42
-
-
Save panchr/95abfea72bd10b104198 to your computer and use it in GitHub Desktop.
Flask Error emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from logging.handlers import SMTPHandler | |
from flask import Flask | |
app = Flask(__name__) # configure however you normally do | |
app.debug = False | |
if not app.debug: | |
logging.basicConfig(level = logging.INFO) | |
handler = SMTPHandler( | |
mailhost = ("smtp.mailgun.org", 587), # your SMTP server goes here; I'm using Mailgun | |
fromaddr = "Application Bug Reporter <{{ email_here }}>", | |
toaddrs = ['{{ admin emails here }}'], | |
subject = "Application Logging Email", | |
credentials = ("{{ SMTP username }}", '{{ SMTP password }}') | |
) | |
handler.setLevel(logging.ERROR) | |
app.logger.addHandler(handler) | |
@app.route("/") | |
def index(): | |
print name # this raises a NameError, which should be emailed to me | |
return "Hello, world!" | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment