src\stacosys\service\mail.py broad-exception-caught
Catching Exception might hide unexpected exceptions, like those that might be raised due to future modification. Therefore, it is recommended to narrow the exceptions. The method send of the class Mailer catches Exception in line 57. MIMEText does not raise exceptions (if not using attachments). See https://docs.python.org/3/library/email.mime.html Most code is handled in an inner exception handling. In order to catch exception from SMTP_SSL I used SMTPException See https://docs.python.org/3/library/smtplib.html
This commit is contained in:
parent
dc776881e4
commit
25ed2f06e0
1 changed files with 2 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
import logging
|
||||
from email.mime.text import MIMEText
|
||||
from smtplib import SMTP_SSL, SMTPAuthenticationError
|
||||
from smtplib import SMTP_SSL, SMTPAuthenticationError, SMTPException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -54,6 +54,6 @@ class Mailer:
|
|||
|
||||
server.send_message(msg)
|
||||
return True
|
||||
except Exception:
|
||||
except SMTPException:
|
||||
logger.error("Error sending email", exc_info=True)
|
||||
return False
|
||||
|
|
Loading…
Add table
Reference in a new issue