Skip to content

[client] add send_email operation in client (opencti #11487) #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pycti/entities/opencti_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
14 changes: 14 additions & 0 deletions pycti/utils/opencti_stix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,18 @@ def organization_unshare(self, item):
item["id"], organization_ids, sharing_direct_container
)

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"
Expand Down Expand Up @@ -2665,6 +2677,8 @@ def apply_opencti_operation(self, item, operation):
self.opencti.stix_core_object.ask_enrichments(
element_id=item["id"], connector_ids=connector_ids
)
elif operation == "send_email":
self.send_email(item=item)
else:
raise ValueError(
"Not supported opencti_operation",
Expand Down