Commit e4f1ce96 authored by Simon Sapin's avatar Simon Sapin

Add support for SMTP authentication for email notification

CC 23bbee82
parent 0f2c4e06
......@@ -88,6 +88,8 @@ DEFAULT_CONFIG = {
"send_email": False,
"smtp_server": 'localhost',
"smtp_port": 25,
"smtp_username": None,
"smtp_password": None,
"smtp_from": "",
"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):
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):
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