Skip to content

Commit 350a841

Browse files
committed
[client] add send_email operation in client
1 parent 269ec1c commit 350a841

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pycti/entities/opencti_user.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,30 @@ def token_renew(self, **kwargs) -> Optional[Dict]:
785785
result["data"]["userEdit"]["tokenRenew"]
786786
)
787787

788+
def send_mail(self, **kwargs):
789+
id = kwargs.get("id", None)
790+
template_id = kwargs.get("template_id", None)
791+
if id is None or template_id is None:
792+
self.opencti.admin_logger.error(
793+
"[opencti_user] Missing parameters: id and template_id"
794+
)
795+
796+
self.opencti.admin_logger.info(
797+
"Send email to user", {"id": id, "template_id": template_id}
798+
)
799+
input = {
800+
"target_user_id": id,
801+
"email_template_id": template_id,
802+
"email_object": template_id,
803+
}
804+
query = """
805+
mutation SendUserMail(input: SendUserMailInput!) {
806+
sendUserMail(input: $input) {
807+
}
808+
}
809+
"""
810+
self.opencti.query(query, {"input": input})
811+
788812
def process_multiple_fields(self, data):
789813
if "roles" in data:
790814
data["roles"] = self.opencti.process_multiple(data["roles"])

pycti/utils/opencti_stix2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,18 @@ def element_remove_groups(self, item):
26462646
{"type": item["type"]},
26472647
)
26482648

2649+
def send_email(self, item):
2650+
template_id = self.opencti.get_attribute_in_extension("template_id", item)
2651+
if template_id is None:
2652+
template_id = item["template_id"]
2653+
if item["type"] == "user":
2654+
self.opencti.user.send_mail(id=item["id"], template_id=template_id)
2655+
else:
2656+
raise ValueError(
2657+
"Not supported opencti_operation for this type",
2658+
{"type": item["type"]},
2659+
)
2660+
26492661
def element_operation_delete(self, item, operation):
26502662
# If data is stix, just use the generic stix function for deletion
26512663
force_delete = operation == "delete_force"
@@ -2736,6 +2748,8 @@ def apply_opencti_operation(self, item, operation):
27362748
self.element_add_groups(item)
27372749
elif operation == "remove_groups":
27382750
self.element_remove_groups(item)
2751+
elif operation == "send_email":
2752+
self.send_email(item=item)
27392753
else:
27402754
raise ValueError(
27412755
"Not supported opencti_operation",

0 commit comments

Comments
 (0)