Skip to content

Commit

Permalink
Merge pull request #128 from marianoleonardo/master
Browse files Browse the repository at this point in the history
Merge branch 'release/v0.7.1' into 'master'
  • Loading branch information
marianoleonardo committed Mar 9, 2022
2 parents 2e2e50e + 6217f71 commit b661be1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ environment.
| AUTH_EMAIL_PASSWD | SMTP password. | empty string | string
| AUTH_EMAIL_PORT | SMTP server port. | 587 | number
| AUTH_EMAIL_TLS | Whether to enable TLS or not for SMTP server. | True | boolean
| AUTH_EMAIL_SERVER_AUTHENTICATION | Whether to enable authentication or not for SMTP server. | True | boolean
| AUTH_EMAIL_USER | SMTP user. | empty string | string
| AUTH_KONG_URL | Kong location (If set to `DISABLED` Auth won´t try to configure Kong and will generate secrets for the JWT tokens by itself). | http://kong:8001 | hostname/IP:port or DISABLE
| AUTH_PASSWD_BLACKLIST | File of blacklisted passwords. | password_blacklist.txt | string
Expand Down
3 changes: 3 additions & 0 deletions auth/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
['true', 'True', 'TRUE'])
emailUsername = os.environ.get("AUTH_EMAIL_USER", "")
emailPasswd = os.environ.get("AUTH_EMAIL_PASSWD", "")
# Whether to enable authentication or not for SMTP server
emailServerAuth = (os.environ.get("AUTH_EMAIL_SERVER_AUTHENTICATION", "true") in
['true', 'True', 'TRUE'])

# if you are using a front end with Auth,
# define this link to point to the password reset view on you FE
Expand Down
16 changes: 12 additions & 4 deletions auth/utils/emailUtils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import smtplib
from email.mime.text import MIMEText
from dojot.module import Log

import conf

LOGGER = Log().color_log()


def send_mail(to, subject, html_msg):
if conf.emailHost == 'NOEMAIL':
return

LOGGER.info("Starting service of sending email")

# TODO: I think we should put this function in a worker thread
msg = MIMEText(html_msg, 'html')

Expand All @@ -16,12 +22,14 @@ def send_mail(to, subject, html_msg):

try:
s = smtplib.SMTP(conf.emailHost, conf.emailPort)
if conf.emailTLS:
if conf.emailTLS and conf.emailServerAuth:
s.starttls()
s.login(conf.emailUsername, conf.emailPasswd)
s.sendmail(conf.emailUsername, [to], msg.as_string())
if conf.emailServerAuth:
s.login(msg['From'], conf.emailPasswd)
s.sendmail(msg['From'], [msg['To']], msg.as_string())
s.quit()
except OSError:
except OSError as error:
LOGGER.error(error)
raise Exception('Failed to retrieve SMTP socket. Is the SMTP port closed?')
except smtplib.SMTPAuthenticationError:
raise Exception('SMTP authentication failed')
Expand Down

0 comments on commit b661be1

Please sign in to comment.