core/source/notification_channels/email.py

56 lines
1.1 KiB
Python
Raw Normal View History

2022-11-29 23:53:14 +01:00
class implementation_notification_channel_email(interface_notification_channel):
'''
[implementation]
'''
def normalize_conf_node(self, node):
return dict_merge(
{
},
node
)
2022-11-29 23:53:14 +01:00
'''
[implementation]
'''
def notify(self, parameters, name, data, state, output):
smtp_connection = _smtplib.SMTP(
parameters["access"]["host"]
)
smtp_connection.login(
parameters["access"]["username"],
parameters["access"]["password"]
)
message = MIMEText(
string_coin(
("(no infos)" if (output is None) else output),
{
}
)
)
message["Subject"] = string_coin(
"{{tags}} {{title}}",
{
"tags": " ".join(
map(
lambda tag: ("[%s]" % tag.upper()),
(
parameters["tags"]
+
[condition_encode(state["condition"])]
)
)
),
"title": data["title"],
}
)
message["From"] = parameters["sender"]
message["To"] = ",".join(parameters["receivers"])
smtp_connection.sendmail(
parameters["sender"],
parameters["receivers"],
message.as_string()
)
smtp_connection.quit()