Commit 822daed4 authored by Phyks's avatar Phyks

Merge branch 'auth' into 'master'

Add support for SMTP authentication for email notification

See merge request !38
parents 0f2c4e06 e4f1ce96
Pipeline #107251 passed with stage
in 6 minutes and 32 seconds
......@@ -88,6 +88,8 @@ DEFAULT_CONFIG = {
"send_email": False,
"smtp_server": 'localhost',
"smtp_port": 25,
"smtp_username": None,
"smtp_password": None,
"smtp_from": "noreply@flatisfy.org",
"smtp_to": [],
# The web site url, to be used in email notifications. (doesn't matter
......@@ -149,6 +151,8 @@ def validate_config(config, check_with_data):
assert isinstance(config["send_email"], bool)
assert config["smtp_server"] is None or isinstance(config["smtp_server"], str) # noqa: E501
assert config["smtp_port"] is None or isinstance(config["smtp_port"], int) # noqa: E501
assert config["smtp_username"] is None or isinstance(config["smtp_username"], str) # noqa: E501
assert config["smtp_password"] is None or isinstance(config["smtp_password"], str) # noqa: E501
assert config["smtp_to"] is None or isinstance(config["smtp_to"], list)
assert isinstance(config["store_personal_data"], bool)
......
......@@ -16,7 +16,7 @@ from email.utils import formatdate, make_msgid
LOGGER = logging.getLogger(__name__)
def send_email(server, port, subject, _from, _to, txt, html):
def send_email(server, port, subject, _from, _to, txt, html, username=None, password=None):
"""
Send an email
......@@ -33,6 +33,8 @@ def send_email(server, port, subject, _from, _to, txt, html):
return
server = smtplib.SMTP(server, port)
if username or password:
server.login(username or "", password or "")
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
......@@ -110,4 +112,6 @@ def send_notification(config, flats):
config["smtp_from"],
config["smtp_to"],
txt,
html)
html,
config.get("smtp_username"),
config.get("smtp_password"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment