File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,29 @@ class ProductionConfig(Config):
4242 SQLALCHEMY_DATABASE_URI = os .environ .get ('DATABASE_URL' ) or \
4343 'sqlite:///' + os .path .join (basedir , 'data.sqlite' )
4444
45+ @classmethod
46+ def init_app (cls , app ):
47+ Config .init_app (app )
48+
49+ # email errors to the administrators
50+ import logging
51+ from logging .handlers import SMTPHandler
52+ credentials = None
53+ secure = None
54+ if getattr (cls , 'MAIL_USERNAME' , None ) is not None :
55+ credentials = (cls .MAIL_USERNAME , cls .MAIL_PASSWORD )
56+ if getattr (cls , 'MAIL_USE_TLS' , None ):
57+ secure = ()
58+ mail_handler = SMTPHandler (
59+ mailhost = (cls .MAIL_SERVER , cls .MAIL_PORT ),
60+ fromaddr = cls .FLASKY_MAIL_SENDER ,
61+ toaddrs = [cls .FLASKY_ADMIN ],
62+ subject = cls .FLASKY_MAIL_SUBJECT_PREFIX + ' Application Error' ,
63+ credentials = credentials ,
64+ secure = secure )
65+ mail_handler .setLevel (logging .ERROR )
66+ app .logger .addHandler (mail_handler )
67+
4568
4669config = {
4770 'development' : DevelopmentConfig ,
You can’t perform that action at this time.
0 commit comments