Skip to content

Instantly share code, notes, and snippets.

@panchr
Last active August 31, 2015 02:42
Show Gist options
  • Save panchr/95abfea72bd10b104198 to your computer and use it in GitHub Desktop.
Save panchr/95abfea72bd10b104198 to your computer and use it in GitHub Desktop.
Flask Error emails
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