From 350a841ba7310ee1b9a91d8fa808c09d862e2132 Mon Sep 17 00:00:00 2001 From: Jeremy Cloarec Date: Wed, 16 Jul 2025 16:51:22 +0200 Subject: [PATCH 1/4] [client] add send_email operation in client --- pycti/entities/opencti_user.py | 24 ++++++++++++++++++++++++ pycti/utils/opencti_stix2.py | 14 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pycti/entities/opencti_user.py b/pycti/entities/opencti_user.py index 1e1006d23..001cd4f7b 100644 --- a/pycti/entities/opencti_user.py +++ b/pycti/entities/opencti_user.py @@ -785,6 +785,30 @@ def token_renew(self, **kwargs) -> Optional[Dict]: result["data"]["userEdit"]["tokenRenew"] ) + def send_mail(self, **kwargs): + id = kwargs.get("id", None) + template_id = kwargs.get("template_id", None) + if id is None or template_id is None: + self.opencti.admin_logger.error( + "[opencti_user] Missing parameters: id and template_id" + ) + + self.opencti.admin_logger.info( + "Send email to user", {"id": id, "template_id": template_id} + ) + input = { + "target_user_id": id, + "email_template_id": template_id, + "email_object": template_id, + } + query = """ + mutation SendUserMail(input: SendUserMailInput!) { + sendUserMail(input: $input) { + } + } + """ + self.opencti.query(query, {"input": input}) + def process_multiple_fields(self, data): if "roles" in data: data["roles"] = self.opencti.process_multiple(data["roles"]) diff --git a/pycti/utils/opencti_stix2.py b/pycti/utils/opencti_stix2.py index 18189a802..a02311184 100644 --- a/pycti/utils/opencti_stix2.py +++ b/pycti/utils/opencti_stix2.py @@ -2646,6 +2646,18 @@ def element_remove_groups(self, item): {"type": item["type"]}, ) + def send_email(self, item): + template_id = self.opencti.get_attribute_in_extension("template_id", item) + if template_id is None: + template_id = item["template_id"] + if item["type"] == "user": + self.opencti.user.send_mail(id=item["id"], template_id=template_id) + else: + raise ValueError( + "Not supported opencti_operation for this type", + {"type": item["type"]}, + ) + def element_operation_delete(self, item, operation): # If data is stix, just use the generic stix function for deletion force_delete = operation == "delete_force" @@ -2736,6 +2748,8 @@ def apply_opencti_operation(self, item, operation): self.element_add_groups(item) elif operation == "remove_groups": self.element_remove_groups(item) + elif operation == "send_email": + self.send_email(item=item) else: raise ValueError( "Not supported opencti_operation", From 0f345c4e69b04d57abccf6779bd34a75630f0a6e Mon Sep 17 00:00:00 2001 From: Jeremy Cloarec Date: Thu, 24 Jul 2025 17:16:15 +0200 Subject: [PATCH 2/4] [client] fix sendUserMail query --- pycti/entities/opencti_user.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pycti/entities/opencti_user.py b/pycti/entities/opencti_user.py index 001cd4f7b..f6528d463 100644 --- a/pycti/entities/opencti_user.py +++ b/pycti/entities/opencti_user.py @@ -799,10 +799,9 @@ def send_mail(self, **kwargs): input = { "target_user_id": id, "email_template_id": template_id, - "email_object": template_id, } query = """ - mutation SendUserMail(input: SendUserMailInput!) { + mutation SendUserMail($input: SendUserMailInput!) { sendUserMail(input: $input) { } } From b6ee036bc4426c92684f8865bf4f77c2dead6390 Mon Sep 17 00:00:00 2001 From: Jeremy Cloarec Date: Fri, 25 Jul 2025 09:57:12 +0200 Subject: [PATCH 3/4] [client] fix send_mail mutation --- pycti/entities/opencti_user.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pycti/entities/opencti_user.py b/pycti/entities/opencti_user.py index f6528d463..9386db388 100644 --- a/pycti/entities/opencti_user.py +++ b/pycti/entities/opencti_user.py @@ -802,9 +802,8 @@ def send_mail(self, **kwargs): } query = """ mutation SendUserMail($input: SendUserMailInput!) { - sendUserMail(input: $input) { + sendUserMail(input: $input) } - } """ self.opencti.query(query, {"input": input}) From 30bba5c028a27cc7e71a00270f5ed524afdf4c5b Mon Sep 17 00:00:00 2001 From: Jeremy Cloarec Date: Fri, 25 Jul 2025 10:07:58 +0200 Subject: [PATCH 4/4] [client] fix send_mail mutation --- pycti/utils/opencti_stix2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycti/utils/opencti_stix2.py b/pycti/utils/opencti_stix2.py index a02311184..e4959a9fd 100644 --- a/pycti/utils/opencti_stix2.py +++ b/pycti/utils/opencti_stix2.py @@ -2651,7 +2651,7 @@ def send_email(self, item): if template_id is None: template_id = item["template_id"] if item["type"] == "user": - self.opencti.user.send_mail(id=item["id"], template_id=template_id) + self.opencti.user.send_mail(id=item["id"], template_id=template_id[0]) else: raise ValueError( "Not supported opencti_operation for this type",