45 lines
967 B
Python
45 lines
967 B
Python
|
|
class implementation_notification_channel_email(interface_notification_channel):
|
||
|
|
|
||
|
|
'''
|
||
|
|
[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()
|