core/source/logic/channels/email.py

111 lines
2 KiB
Python
Raw Normal View History

2022-11-29 23:53:14 +01:00
class implementation_notification_channel_email(interface_notification_channel):
'''
[implementation]
'''
def parameters_schema(self):
return {
"type": "object",
"additionalProperties": False,
"properties": {
"access": {
"type": "object",
"additionalProperties": False,
"properties": {
"host": {
"type": "string"
},
"port": {
"type": "integer"
},
"username": {
"type": "string"
},
"password": {
"type": "string"
}
},
"required": [
"host",
"port",
"username",
"password"
]
},
"sender": {
"type": "string"
},
"receivers": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": {
"description": "list of strings, which will be placed in the e-mail subject",
"type": "array",
"items": {
"type": "string"
},
"default": []
}
},
"required": [
"access",
"sender",
"receivers"
]
}
'''
[implementation]
'''
def normalize_conf_node(self, node):
return dict_merge(
{
},
node
)
2022-11-29 23:53:14 +01:00
'''
[implementation]
'''
2022-11-30 23:14:38 +01:00
def notify(self, parameters, name, data, state, info):
2022-11-29 23:53:14 +01:00
smtp_connection = _smtplib.SMTP(
parameters["access"]["host"]
)
smtp_connection.login(
parameters["access"]["username"],
parameters["access"]["password"]
)
message = MIMEText(
_json.dumps(info, indent = "\t", ensure_ascii = False)
2022-11-29 23:53:14 +01:00
)
message["Subject"] = string_coin(
"{{tags}} {{title}}",
{
"tags": " ".join(
map(
lambda tag: ("[%s]" % tag.upper()),
(
parameters["tags"]
+
[condition_show(state["condition"])]
2022-11-29 23:53:14 +01:00
)
)
),
"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()
2022-11-30 23:14:38 +01:00