Merge branch 'auth' into 'master'
Add support for SMTP authentication for email notification See merge request phyks/Flatisfy!38
This commit is contained in:
commit
822daed43e
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user