Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL/TLS support and authentication for SMTP #2940

Merged
merged 7 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/timesketch.conf
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ EMAIL_RECIPIENTS = []
# Configuration to construct URLs for resources.
EXTERNAL_HOST_URL = 'https://localhost'

# SSL/TLS support for emails
EMAIL_TLS = False
EMAIL_SSL = False

# Email support for authentication
EMAIL_AUTH_USERNAME = ""
EMAIL_AUTH_PASSWORD = ""

#-------------------------------------------------------------------------------
# Sigma Settings

Expand Down
27 changes: 27 additions & 0 deletions timesketch/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ def send_email(subject, body, to_username, use_html=False):
email_smtp_server = current_app.config.get("EMAIL_SMTP_SERVER")
email_from_user = current_app.config.get("EMAIL_FROM_ADDRESS", "timesketch")
email_user_whitelist = current_app.config.get("EMAIL_USER_WHITELIST", [])
email_login_username = current_app.config.get("EMAIL_AUTH_USERNAME")
email_login_password = current_app.config.get("EMAIL_AUTH_PASSWORD")
email_ssl = current_app.config.get("EMAIL_SSL")
email_tls = current_app.config.get("EMAIL_TLS")

if not email_enabled:
raise RuntimeError("Email notifications are not enabled, aborting.")
Expand Down Expand Up @@ -626,6 +630,29 @@ def send_email(subject, body, to_username, use_html=False):
msg.add_header("Content-Type", email_content_type)
msg.set_payload(body)

# EMAIL_SSL in timesketch.conf must be set to True
if email_ssl:
smtp = smtplib.SMTP_SSL(email_smtp_server)
if email_login_username and email_login_password:
smtp.login(email_login_username, email_login_password)
smtp.sendmail(msg["From"], [msg["To"]], msg.as_string())
smtp.quit()
return

berggren marked this conversation as resolved.
Show resolved Hide resolved
# EMAIL_TLS in timesketch.conf must be set to True
if email_tls:
smtp = smtplib.SMTP(email_smtp_server)
smtp.ehlo()
smtp.starttls()
if email_login_username and email_login_password:
smtp.login(email_login_username, email_login_password)
smtp.sendmail(msg["From"], [msg["To"]], msg.as_string())
smtp.quit()
return

# default - no SSL/TLS configured
smtp = smtplib.SMTP(email_smtp_server)
if email_login_username and email_login_password:
smtp.login(email_login_username, email_login_password)
smtp.sendmail(msg["From"], [msg["To"]], msg.as_string())
smtp.quit()
Loading