feat: add SMTP {port, use_tls} config (#1142)

* feat: add SMTP {port, use_tls} config
* If `password` is None don't attempt to log in
* remove 'can be omitted' comment

---------
Co-authored-by: Ilya Kreymer <ikreymer@users.noreply.github.com>
This commit is contained in:
Anish Lakhwara 2023-09-08 08:18:36 -07:00 committed by GitHub
parent e75b207f7e
commit e57148d0e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -16,6 +16,8 @@ class EmailSender:
self.password = os.environ.get("EMAIL_PASSWORD")
self.reply_to = os.environ.get("EMAIL_REPLY_TO") or self.sender
self.smtp_server = os.environ.get("EMAIL_SMTP_HOST")
self.smtp_port = int(os.environ.get("EMAIL_SMTP_PORT", 587))
self.smtp_use_tls = bool(os.environ.get("EMAIL_SMTP_USE_TLS", True))
self.default_origin = os.environ.get("APP_ORIGIN")
@ -35,11 +37,13 @@ class EmailSender:
msg.set_content(message)
context = ssl.create_default_context()
with smtplib.SMTP(self.smtp_server, 587) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(self.sender, self.password)
with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
if self.smtp_use_tls:
server.ehlo()
server.starttls(context=context)
server.ehlo()
if self.password is not None:
server.login(self.sender, self.password)
server.send_message(msg)
# server.sendmail(self.sender, receiver, message)

View File

@ -14,6 +14,7 @@ stringData:
EMAIL_SENDER: "{{ .Values.email.sender_email }}"
EMAIL_REPLY_TO: "{{ .Values.email.reply_to }}"
EMAIL_PASSWORD: "{{ .Values.email.password }}"
EMAIL_SMTP_USE_TLS: "{{ .Values.email.use_tls }}"
SUPERUSER_EMAIL: "{{ .Values.superuser.email }}"
SUPERUSER_PASSWORD: "{{ .Values.superuser.password }}"

View File

@ -282,6 +282,7 @@ email:
sender_email: example@example.com
password: password
reply_to_email: example@example.com
use_tls: True
# Deployment options