feat(chalice): SMTP change
This commit is contained in:
parent
6d7a0ea740
commit
843c41971d
1 changed files with 7 additions and 1 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import smtplib
|
||||
from smtplib import SMTPAuthenticationError
|
||||
|
||||
from decouple import config
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
|
||||
class EmptySMTP:
|
||||
|
|
@ -31,7 +34,10 @@ class SMTPClient:
|
|||
# stmplib docs recommend calling ehlo() before & after starttls()
|
||||
self.server.ehlo()
|
||||
if len(config("EMAIL_USER", default="")) > 0 and len(config("EMAIL_PASSWORD", default="")) > 0:
|
||||
self.server.login(user=config("EMAIL_USER"), password=config("EMAIL_PASSWORD"))
|
||||
try:
|
||||
self.server.login(user=config("EMAIL_USER"), password=config("EMAIL_PASSWORD"))
|
||||
except SMTPAuthenticationError:
|
||||
raise HTTPException(401, "SMTP Authentication Error")
|
||||
return self.server
|
||||
|
||||
def __exit__(self, *args):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue