2022-11-29 23:53:14 +01:00
|
|
|
class implementation_notification_channel_email(interface_notification_channel):
|
|
|
|
|
|
2022-11-30 10:26:27 +01:00
|
|
|
'''
|
|
|
|
|
[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()
|