Skip to content

Commit ed203c2

Browse files
committed
[client] add send_email operation in client
1 parent b5cbbb3 commit ed203c2

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
@@ -2583,6 +2583,18 @@ def organization_unshare(self, item):
25832583
item["id"], organization_ids, sharing_direct_container
25842584
)
25852585

2586+
def send_email(self, item):
2587+
template_id = self.opencti.get_attribute_in_extension("template_id", item)
2588+
if template_id is None:
2589+
template_id = item["template_id"]
2590+
if item["type"] == "user":
2591+
self.opencti.user.send_mail(id=item["id"], template_id=template_id)
2592+
else:
2593+
raise ValueError(
2594+
"Not supported opencti_operation for this type",
2595+
{"type": item["type"]},
2596+
)
2597+
25862598
def element_operation_delete(self, item, operation):
25872599
# If data is stix, just use the generic stix function for deletion
25882600
force_delete = operation == "delete_force"
@@ -2665,6 +2677,8 @@ def apply_opencti_operation(self, item, operation):
26652677
self.opencti.stix_core_object.ask_enrichments(
26662678
element_id=item["id"], connector_ids=connector_ids
26672679
)
2680+
elif operation == "send_email":
2681+
self.send_email(item=item)
26682682
else:
26692683
raise ValueError(
26702684
"Not supported opencti_operation",

0 commit comments

Comments
 (0)