flask-mail icon indicating copy to clipboard operation
flask-mail copied to clipboard

Not setting MAIL_DEBUG while DEBUG=true results in an error

Open iandees opened this issue 7 years ago • 3 comments

The code calls int() on the setting of MAIL_DEBUG, which defaults to app.debug, which isn't an integer value normally. When it's "true", it results in a ValueError:

  File ".../app/__init__.py", line 42, in create_app
    mail.init_app(app)
  File ".../lib/python3.6/site-packages/flask_mail.py", line 566, in init_app
    state = self.init_mail(app.config, app.debug, app.testing)
  File ".../lib/python3.6/site-packages/flask_mail.py", line 552, in init_mail
    int(config.get('MAIL_DEBUG', debug)),
ValueError: invalid literal for int() with base 10: 'true'

This can be solved by setting MAIL_DEBUG to something integer-like, but it probably should work by default.

iandees avatar Jul 21 '18 20:07 iandees

@iandees How it happens that you have string value in app.debug ?

It must be either True or False.

sv0 avatar May 02 '20 07:05 sv0

I think my description of the problem was incorrect back then. It doesn't default to app.debug, it first checks config.get('MAIL_DEBUG'), which can be set to whatever type you want when you load a config Python module.

iandees avatar May 02 '20 14:05 iandees

MAIL_DEBUG is used by flask-mail to set the debug output level for smtplib

which can be set to whatever type you want when you load a config Python module.

Accordingly to smtplib documentation, it must be one of 0, False, 1, True, 2, but not whatever type you want.

sv0 avatar May 06 '20 09:05 sv0