remove email debug

This commit is contained in:
Daniel afx 2022-02-05 05:11:16 +02:00
parent 2f0fca383d
commit 526887a324
3 changed files with 4 additions and 24 deletions

View file

@ -12,10 +12,11 @@ POSTGRES_DB=forest_prod
DATABASE_URL=postgresql://forest:forest123@db:5432/forest_prod DATABASE_URL=postgresql://forest:forest123@db:5432/forest_prod
MAIL_ADMIN=daniel@deflax.net
MAIL_SUBJECT_PREFIX=ForestNet
MAIL_SERVER=smtp.gmail.com MAIL_SERVER=smtp.gmail.com
MAIL_USERNAME=admin@gmail.com MAIL_USERNAME=admin@gmail.com
MAIL_PASSWORD=kur MAIL_PASSWORD=kur
MAIL_PORT=25 MAIL_PORT=25
MAIL_SUBJECT_PREFIX=ForestNet
MAIL_ADMIN=daniel@deflax.net
MAIL_USE_TLS=1 MAIL_USE_TLS=1

View file

@ -105,26 +105,5 @@ def service_unavailable(e):
def handle_csrf_error(e): def handle_csrf_error(e):
return render_template('errors/csrf_error.html', reason=e.description), 400 return render_template('errors/csrf_error.html', reason=e.description), 400
if not app.config['DEBUG'] == 1 and app.config['MAIL_SERVER'] != '':
import logging
from logging.handlers import SMTPHandler
credentials = None
secure = None
if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
credentials = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD'])
if app.config['MAIL_USE_TLS'] is None:
secure = ()
mail_handler = SMTPHandler(
mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
fromaddr=app.config['MAIL_SENDER'],
toaddrs=[app.config['MAIL_ADMIN']],
subject=app.config['MAIL_SUBJECT_PREFIX'] + ' Application Error',
credentials=credentials,
secure=secure)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run()

View file

@ -15,7 +15,7 @@ def send_email(to, subject, template, **kwargs):
else: else:
newsubject = subject newsubject = subject
app = current_app._get_current_object() app = current_app._get_current_object()
msg = Message(app.config['MAIL_SUBJECT_PREFIX'] + ' ' + newsubject, sender=app.config['MAIL_SENDER'], recipients=[to]) msg = Message(app.config['MAIL_SUBJECT_PREFIX'] + ' ' + newsubject, sender=app.config['MAIL_ADMIN'], recipients=[to])
msg.body = render_template(template + '.txt', **kwargs) msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs) msg.html = render_template(template + '.html', **kwargs)
thr = Thread(target=send_async_email, args=[app, msg]) thr = Thread(target=send_async_email, args=[app, msg])