diff --git a/pycti/entities/opencti_user.py b/pycti/entities/opencti_user.py index 1e1006d2..f6528d46 100644 --- a/pycti/entities/opencti_user.py +++ b/pycti/entities/opencti_user.py @@ -785,6 +785,29 @@ 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, + } + 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 18189a80..a0231118 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",