Microsoft Graph Mail Single User
Microsoft Graph grants Cortex XSOAR authorized access to a user's Microsoft Outlook mail data in a personal account or organization account.
Email · Microsoft Graph Mail
Details
| ID | Microsoft Graph Mail Single User |
|---|---|
| Provider | Microsoft |
| Category | |
| From Version | 5.0.0 |
| Docker Image | demisto/crypto:1.0.0.10120494 |
| Supported Modules | Agentix Cloud Runtime Security XSIAM EDR Cortex Cloud |
README
Microsoft Graph grants Cortex XSOAR authorized access to a user’s Microsoft Outlook mail data in a personal account or organization account.
This integration was integrated and tested with version 1.0 of Microsoft Graph Mail Single User
Note: This integration operates against a single user mailbox — the one specified in the Email address to associate for this integration. configuration parameter. Because it uses delegated permissions, it cannot access other users’ mailboxes. For multi-mailbox or cross-tenant access, use the Microsoft Graph Mail (multi-tenant) integration.
Fetch Incidents
The integration imports email messages from the destination folder in the target mailbox as incidents. If the message contains any attachments, they are uploaded to the War Room as files. If the attachment is an email (item attachment), Cortex XSOAR fetches information about the attached email and downloads all of its attachments (if there are any) as files. To use Fetch incidents, configure a new instance and select the Fetches incidents option in the instance settings.
OData Usage
The OData parameter can be used to create different queries for the msgraph-mail-list-emails and msgraph-mail-get-email commands. Please see OData Docs for detailed information.
Examples:
!msgraph-mail-list-emails odata="$select=from"
!msgraph-mail-list-emails odata="$filter=from/emailAddress/address eq 'azure-noreply@microsoft.com'"
!msgraph-mail-list-emails odata="$filter=sentDateTime gt 2020-03-25T09:35:23Z and sentDateTime lt 2020-03-25T12:04:47Z"
Note:
The query parameter $filter is not supported when using the search parameter.
Authentication
For more details about the authentication used in this integration, see Microsoft Integrations - Authentication.
Note - The credentials (created by the Cortex XSOAR application) are valid for a single instance only.
Note - When authenticating with the Cortex application, sign in with the same user you want to integrate with. Since this user must grant consent for the app’s permissions, they must be an administrator. To let a non-admin user use the app instead, after an admin has consented to the application once, go to the Azure Portal > Enterprise applications, find the app, and set Assignment required? to No. This way, other users can obtain the Cortex application credentials without needing to sign in or consent themselves. Alternatively, you can use a Self-Deployed Application.
Email Attachments Limitations
- The maximum attachment size to be sent in an email can be 150-MB. large-attachments
- The larger the attachment, the longer it would take for a command that supports adding attachments to run.
- Requires the permission of Mail.ReadWrite (Application) - to send attachments > 3mb
- When sending mails with large attachments, it could take up to 5 minutes for the mail to actually be sent.
Required Permissions
The following permissions are required for all commands:
- Mail.ReadWrite - Delegated
- Mail.Send - Delegated
- User.Read - Delegated
- MailboxSettings.ReadWrite - Delegated
The following permissions are required for Shared Mailbox:
- Mail.Read.Shared
- Mail.ReadBasic.Shared
- Mail.ReadWrite.Shared
- Mail.Send.Shared
Configure Microsoft Graph Mail Single User in Cortex
| Parameter | Description | Required |
|---|---|---|
| ID or Client ID | False | |
| Token or Tenant ID | False | |
| Key or Client Secret | False | |
| ID or Client ID - see Detailed Instructions (?) | False | |
| Token or Tenant ID - see Detailed Instructions (?) | False | |
| Key or Client Secret - see Detailed Instructions (?) | False | |
| Certificate Thumbprint (optional for self-deployed Azure app) | False | |
| Private Key | False | |
| Certificate Thumbprint (optional for self-deployed Azure app) | Used for certificate authentication. As appears in the “Certificates & secrets” page of the app. | False |
| Private Key | Used for certificate authentication. The private key of the registered certificate. | False |
| Authorization code (required for self-deployed Azure app) | False | |
| Application redirect URI (required for self-deployed Azure app) | False | |
| Use Azure Managed Identities | Relevant only if the integration is running on Azure VM. If selected, authenticates based on the value provided for the Azure Managed Identities Client ID field. If no value is provided for the Azure Managed Identities Client ID field, authenticates based on the System Assigned Managed Identity. For additional information, see the Help tab. | False |
| Azure Managed Identities Client ID | The Managed Identities client ID for authentication - relevant only if the integration is running on Azure VM. | False |
| Fetch incidents | False | |
| Email address from which to fetch incidents (e.g., “example@demisto.com”) | During authentication, ensure you are logged in to this email address. | True |
| Name of the folder from which to fetch incidents (supports Folder ID and sub-folders e.g., Inbox/Phishing) | True | |
| First fetch timestamp (<number> <time unit>, e.g., 12 hours, 7 days) | False | |
| Maximum number of emails to pull per fetch | False | |
| Trust any certificate (not secure) | False | |
| Use system proxy settings | False | |
| Use a self-deployed Azure application | Select this checkbox if you are using a self-deployed Azure application. | False |
| Incident type | False | |
| Display full email body | If not active, only a preview of the email will be fetched. | False |
| Fetch emails in HTML format | Select this checkbox to retrieve the body of an email in HTML format. If this checkbox is not selected, a psuedo-text representation of HTML emails will be returned and some functionality in other packs (e.g., email previews in the Email Communication pack) may not provide their full capabilities. | False |
| Mark fetched emails as read | Relevant only if fetch incidents is active. | False |
| Incidents Fetch Interval | False |
Commands
You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.
msgraph-mail-create-draft
Creates a draft message in the specified user’s mailbox.
Base Command
msgraph-mail-create-draft
Input
| Argument Name | Description | Required |
|---|---|---|
| to | A comma-separated list of email addresses for the ‘to’ field. | Optional |
| cc | A comma-separated list of email addresses for the ‘cc’ field. | Optional |
| bcc | A comma-separated list of email addresses for the ‘bcc’ field. | Optional |
| subject | The subject for the draft. | Required |
| body | The contents (body) of the draft. | Optional |
| body_type | The body type of the email. Can be: “text”, or “HTML”. Possible values are: text, HTML. Default is text. | Optional |
| flag | The flag value that indicates the status of the draft. Possible values are: notFlagged, complete, flagged. Default is notFlagged. | Optional |
| importance | The importance of the draft. Possible values are: Low, Normal, High. Default is Low. | Optional |
| headers | A comma-separated list of additional headers in the format, headerName:headerValue. For example, “headerName1:headerValue1,headerName2:headerValue2”. | Optional |
| attach_ids | A comma-separated list of War Room entry IDs that contain files, which are used to attach files to the draft. For example, attachIDs=15@8,19@8. | Optional |
| attach_names | A comma-separated list of names of attachments to be displayed in the draft. Must be the same number of elements as attachIDs. | Optional |
| attach_cids | A comma-separated list of CIDs to embed attachments within the actual email. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MicrosoftGraph.Draft.Cc | String | The CC recipients of the draft email. |
| MicrosoftGraph.Draft.IsRead | String | The “Is read” status of the draft email. |
| MicrosoftGraph.Draft.Bcc | String | The BCC recipients of the draft email. |
| MicrosoftGraph.Draft.Body | String | The body of the draft email. |
| MicrosoftGraph.Draft.MessageID | String | The message ID of the draft email. |
| MicrosoftGraph.Draft.SentTime | Date | The sent time of the draft email. |
| MicrosoftGraph.Draft.Headers | String | The headers of the draft email. |
| MicrosoftGraph.Draft.From | String | The user that sent the draft email. |
| MicrosoftGraph.Draft.Subject | String | The subject of the draft email. |
| MicrosoftGraph.Draft.ReceivedTime | String | The received time of the draft email. |
| MicrosoftGraph.Draft.Importance | String | The importance status of the draft email. |
| MicrosoftGraph.Draft.CreatedTime | String | The created time of the draft email. |
| MicrosoftGraph.Draft.Sender | String | The sender of the draft email. |
| MicrosoftGraph.Draft.ModifiedTime | Date | The modified time of the draft email. |
| MicrosoftGraph.Draft.IsDraft | Boolean | Whether it is a draft email. |
| MicrosoftGraph.Draft.ID | String | The ID of the draft email. |
| MicrosoftGraph.Draft.To | String | The ‘to’ recipients of the draft email. |
| MicrosoftGraph.Draft.BodyType | Unknown | The body type of the draft email. |
| MicrosoftGraph.Draft.ConversationID | String | The conversation ID of the draft email. |
reply-mail
Replies to an email using Graph Mail Single User.
Required Permissions
The following permissions are required for this command:
- Mail.Send (Application)
- Mail.ReadWrite (Application) - to send attachments > 3mb
Base Command
reply-mail
Input
| Argument Name | Description | Required |
|---|---|---|
| to | A comma-separated list of email addresses for the ‘to’ field. | Required |
| body | The contents (body) of the email to be sent. | Optional |
| subject | Subject for the email to be sent. | Required |
| inReplyTo | ID of the item to reply to. | Required |
| attachIDs | A comma-separated list of War Room entry IDs that contain files, and are used to attach files to the outgoing email. For example: attachIDs=15@8,19@8. | Optional |
| cc | A comma-separated list of email addresses for the ‘cc’ field. | Optional |
| bcc | A comma-separated list of email addresses for the ‘bcc’ field. | Optional |
| htmlBody | HTML formatted content (body) of the email to be sent. This argument overrides the “body” argument. | Optional |
| attachNames | A comma-separated list of names of attachments to send. Should be the same number of elements as attachIDs. | Optional |
| attachCIDs | A comma-separated list of CIDs to embed attachments within the email itself. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MicrosoftGraph.SentMail.body | String | The body of the email. |
| MicrosoftGraph.SentMail.bodyPreview | String | The body preview of the email. |
| MicrosoftGraph.SentMail.subject | String | The subject of the email. |
| MicrosoftGraph.SentMail.toRecipients | String | The ‘To’ recipients of the email. |
| MicrosoftGraph.SentMail.ccRecipients | String | The CC recipients of the email. |
| MicrosoftGraph.SentMail.bccRecipients | String | The BCC recipients of the email. |
| MicrosoftGraph.SentMail.ID | String | The immutable ID of the message. |
send-mail
Sends an email using Microsoft Graph.
Required Permissions
The following permissions are required for this command:
- Mail.Send (Application)
- Mail.ReadWrite (Application) - to send attachments > 3mb
Base Command
send-mail
Input
| Argument Name | Description | Required |
|---|---|---|
| to | A comma-separated list of email addresses for the ‘to’ field. | Optional |
| cc | A comma-separated list of email addresses for the ‘cc’ field. | Optional |
| bcc | A comma-separated list of email addresses for the ‘bcc’ field. | Optional |
| subject | The subject of the email. | Required |
| body | The contents (body) of the email. | Optional |
| body_type | The body type of the email. Can be: “text”, or “HTML”. Possible values are: text, HTML. | Optional |
| renderBody | Indicates whether to render the email body. Possible values are: true, false. | Optional |
| flag | The flag value that indicates the status for the email. Possible values are: notFlagged, complete, flagged. Default is notFlagged. | Optional |
| importance | The importance of the email. Possible values are: Low, Normal, High. Default is Low. | Optional |
| headers | A comma-separated list of additional headers in the format: headerName:headerValue. For example: “headerName1:headerValue1,headerName2:headerValue2”. | Optional |
| attach_ids | A comma-separated list of War Room entry IDs that contain files, which are used to attach files for the email to send. For example, attachIDs=15@8,19@8. | Optional |
| attach_names | A comma-separated list of names of attachments to display in the email to send. Must be the same number of elements as attachIDs. | Optional |
| attach_cids | A comma-separated list of CIDs to embed attachments within the actual email. | Optional |
| attachIDs | A comma-separated list of War Room entry IDs that contain files, which are used to attach files for the email to send. For example, attachIDs=15@8,19@8. | Optional |
| attachNames | A comma-separated list of names of attachments to display in the email to send. Must be the same number of elements as attachIDs. | Optional |
| attachCIDs | A comma-separated list of CIDs to embed attachments within the actual email. | Optional |
| replyTo | Email addresses that need to be used to reply to the message. Supports comma-separated values. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MicrosoftGraph.Email.internetMessageHeaders | String | The email headers. |
| MicrosoftGraph.Email.body | String | The body of the email. |
| MicrosoftGraph.Email.bodyPreview | String | The body preview of the email. |
| MicrosoftGraph.Email.subject | String | The subject of the email. |
| MicrosoftGraph.Email.flag | String | The flag status of the email. |
| MicrosoftGraph.Email.importance | String | The importance status of the email. |
| MicrosoftGraph.Email.toRecipients | String | The ‘to’ recipients of the email. |
| MicrosoftGraph.Email.ccRecipients | String | The CC recipients of the email. |
| MicrosoftGraph.Email.bccRecipients | String | The BCC recipients of the email. |
| MicrosoftGraph.Email.replyTo | String | The replyTo recipients of the email. |
msgraph-mail-reply-to
The replies to the recipients of a message.
Base Command
msgraph-mail-reply-to
Input
| Argument Name | Description | Required |
|---|---|---|
| message_id | The ID of the message. | Required |
| comment | The comment of the replied message. | Required |
| to | A comma-separated list of email addresses for the ‘to’ field. | Required |
| attach_ids | A comma-separated list of War Room entry IDs that contain files, which are used to attach files for the email to send. For example, attachIDs=15@8,19@8. | Optional |
| attach_names | A comma-separated list of names of attachments to display in the email to send. Must be the same number of elements as attach_ids. | Optional |
| attach_cids | A comma-separated list of CIDs to embed attachments within the actual email. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
There is no context output for this command.
Command Example
msgraph-mail-send-draft
Sends a draft email using Microsoft Graph.
Base Command
msgraph-mail-send-draft
Input
| Argument Name | Description | Required |
|---|---|---|
| draft_id | The ID of the draft email. | Required |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
There is no context output for this command.
msgraph-mail-test
Tests connectivity of the email.
Base Command
msgraph-mail-test
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
There is no context output for this command.
msgraph-mail-auth-reset
Run this command if for some reason you need to rerun the authentication process.
Base Command
msgraph-mail-auth-reset
Input
There are no input arguments for this command.
Context Output
There is no context output for this command.
msgraph-mail-list-emails
Gets the properties of returned emails. Typically shows partial results, use the “page_size” and “pages_to_pull” arguments to get all results. This command lists emails only from the mailbox specified in the integration configuration.
Base Command
msgraph-mail-list-emails
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_id | A comma-separated list of folder IDs, in the format: (mail_box,child_mail_box,child_mail_box). | Optional |
| odata | An OData query. See OData Usage for OData usage examples. | Optional |
| search | The term for which to search. This argument cannot contain reserved characters such as !, $, #, @, etc. For further information, see https://tools.ietf.org/html/rfc3986#section-2.2. | Optional |
| page_size | The maximum number of emails to fetch in one request. Default is 20. | Optional |
| pages_to_pull | The number of pages of emails to return (maximum is 10 emails per page). Default is 1. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.ID | String | The ID of the email. |
| MSGraphMail.Created | Date | The time the email was created. |
| MSGraphMail.LastModifiedTime | Date | The time the email was last modified. |
| MSGraphMail.ReceivedTime | Date | The time the email was received. |
| MSGraphMail.SendTime | Date | The time the email was sent. |
| MSGraphMail.Categories | String | Categories of the email. |
| MSGraphMail.HasAttachments | Boolean | Whether the email has attachments. |
| MSGraphMail.Subject | String | The subject of the email. |
| MSGraphMail.IsDraft | Boolean | Whether the email is a draft. |
| MSGraphMail.Body | String | The content (body) of the email. |
| MSGraphMail.Sender.Name | String | The name of the sender. |
| MSGraphMail.Sender.Address | String | The email address of the sender. |
| MSGraphMail.From.Name | String | The name of the user in the ‘from’ field of the email. |
| MSGraphMail.From.Address | String | The email address of the user in the ‘from’ field of the email. |
| MSGraphMail.CCRecipients.Name | String | The names of the CC recipients. |
| MSGraphMail.CCRecipients.Address | String | The email address of the user in the ‘cc’ field of the email. |
| MSGraphMail.BCCRecipients.Name | String | The names of the users in the ‘bcc’ field of the email. |
| MSGraphMail.BCCRecipients.Address | String | The email address of the user in the ‘bcc’ field of the email. |
| MSGraphMail.ReplyTo.Name | String | The name in the ‘replyTo’ field of the email. |
| MSGraphMail.ReplyTo.Address | String | The email address in the ‘replyTo’ field of the email. |
| MSGraphMail.UserID | String | The ID of the user. |
| MSGraphMail.ConversationID | String | The ID of the conversation. |
| MSGraphMail.InternetMessageID | String | Internet Message ID of the message. |
| MSGraphMail.Recipients.Name | String | The name of the user in the ‘toRecipients’ field of the email. |
| MSGraphMail.Recipients.Address | String | The email address of the user in the ‘toRecipients’ field of the email. |
| MSGraphMail.NextPage | String | A token to pass to the next list command to retrieve additional results. |
Command Example
!msgraph-mail-list-emails folder_id=Inbox page_size=20
msgraph-mail-list-attachments
Lists all attachments of an email.
Base Command
msgraph-mail-list-attachments
Input
| Argument Name | Description | Required |
|---|---|---|
| message_id | The email message id. | Required |
| folder_id | The id of the folder. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMailAttachment.ID | String | The email ID. |
| MSGraphMailAttachment.Attachment.ID | String | The ID of the attachment. |
| MSGraphMailAttachment.Attachment.Name | String | The name of the attachment. |
| MSGraphMailAttachment.Attachment.Type | String | The attachment type. |
| MSGraphMailAttachment.UserID | String | The ID of the user. |
msgraph-mail-get-attachment
Gets an attachment from the email.
Base Command
msgraph-mail-get-attachment
Input
| Argument Name | Description | Required |
|---|---|---|
| message_id | The unique ID of the mail. You cannot use the ‘MessageID’ key in the form ‘<message-id>’. | Required |
| folder_id | A comma-separated list of folder IDs, in the format: (mail_box,child_mail_box,child_mail_box). | Optional |
| attachment_id | The ID of the attachment. In case not supplied, the command will return all the attachments. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| File.Size | Number | The size of the file. |
| File.SHA1 | String | The SHA1 hash of the file. |
| File.SHA256 | String | The SHA256 hash of the file. |
| File.Name | String | The name of the file. |
| File.SSDeep | String | The SSDeep hash of the file. |
| File.EntryID | String | The entry ID of the file. |
| File.Info | String | File information. |
| File.Type | String | The file type. |
| File.MD5 | String | The MD5 hash of the file. |
| File.Extension | String | The file extension. |
msgraph-mail-get-email-as-eml
Retrieves an email message by message ID and uploads the content as an EML file.
Base Command
msgraph-mail-get-email-as-eml
Input
| Argument Name | Description | Required |
|---|---|---|
| message_id | The unique ID of the email. You cannot use the ‘MessageID’ key in the form ‘<message-id>’. | Required |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| File.Size | String | The size of the file. |
| File.SHA1 | String | The SHA1 hash of the file. |
| File.SHA256 | String | The SHA256 hash of the file. |
| File.SHA512 | String | The SHA512 hash of the file. |
| File.Name | String | The name of the file. |
| File.SSDeep | String | The SSDeep hash of the file. |
| File.EntryID | String | The EntryID of the file. |
| File.Info | String | Information about the file. |
| File.Type | String | The file type. |
| File.MD5 | String | The MD5 hash of the file. |
| File.Extension | String | The extension of the file. |
msgraph-update-email-status
Update the status of an email to read / unread.
Base Command
msgraph-update-email-status
Input
| Argument Name | Description | Required |
|---|---|---|
| message_ids | Unique ID of the emails to update. You cannot use the ‘MessageID’ key in the form ‘<message-id>’. Can be a list of comma-separated values. | Required |
| folder_id | The folder ID. | Optional |
| status | Status to set the email to. Possible values are: Read, Unread. | Required |
Context Output
There is no context output for this command.
msgraph-mail-generate-login-url
Generate the login url used for Authorization code flow.
Base Command
msgraph-mail-generate-login-url
Input
There are no input arguments for this command.
Context Output
There is no context output for this command.
Command Example
msgraph-mail-generate-login-url
Human Readable Output
Authorization instructions
- Click on the login URL to sign in and grant Cortex XSOAR permissions for your Azure Service Management.
You will be automatically redirected to a link with the following structure:
REDIRECT_URI?code=AUTH_CODE&session_state=SESSION_STATE- Copy the
AUTH_CODE(without thecode=prefix, and thesession_stateparameter)
and paste it in your instance configuration under the Authorization code parameter.
msgraph-mail-create-folder
Creates a new folder under the specified folder (parent).
Base Command
msgraph-mail-create-folder
Input
| Argument Name | Description | Required |
|---|---|---|
| new_folder_name | display name of new folder. | Required |
| parent_folder_id | The ID of the parent folder under which to create a new folder. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.Folders.ChildFolderCount | number | The number of child folders. |
| MSGraphMail.Folders.DisplayName | string | The folder display name. |
| MSGraphMail.Folders.ID | string | The Folder ID. |
| MSGraphMail.Folders.ParentFolderID | string | The parent folder ID. |
| MSGraphMail.Folders.TotalItemCount | number | The total number of email messages in the folder. |
| MSGraphMail.Folders.UnreadItemCount | number | The number of unread email messages in the folder. |
msgraph-mail-move-email
Move a message to another folder. This operation creates a new copy of the message in the destination folder and deletes the original message. As a result, the message ID changes.
Base Command
msgraph-mail-move-email
Input
| Argument Name | Description | Required |
|---|---|---|
| message_id | The unique ID of the mail. You cannot use the the ‘MessageID’ key in the form ‘<message-id>’. | Required |
| destination_folder_id | The ID of the destination folder. | Required |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.MovedEmails.DestinationFolderID | string | The folder where the email message was moved. |
| MSGraphMail.MovedEmails.ID | string | The new ID of the moved email message. |
| MSGraphMail.MovedEmails.UserID | unknown | The user ID. |
msgraph-mail-list-folders
Returns the mail folder list directly under the root folder.
Base Command
msgraph-mail-list-folders
Input
| Argument Name | Description | Required |
|---|---|---|
| limit | The maximum number of mail folder lists to return. Default is 20. | Optional |
| ran_once_flag | Flag for rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.Folders.ChildFolderCount | number | Number of child folders. |
| MSGraphMail.Folders.DisplayName | string | Folder display name. |
| MSGraphMail.Folders.ID | string | Target folder ID. |
| MSGraphMail.Folders.ParentFolderID | string | Parent folder ID. |
| MSGraphMail.Folders.TotalItemCount | number | The total number of email messages in the folder. |
| MSGraphMail.Folders.UnreadItemCount | number | The number of unread emails in the folder. |
msgraph-mail-list-child-folders
Returns the folder list under the specified folder.
Base Command
msgraph-mail-list-child-folders
Input
| Argument Name | Description | Required |
|---|---|---|
| parent_folder_id | The ID of the parent folder. | Required |
| limit | The maximum number of mail folder lists to return. Default is 20. Default is 20. | Optional |
| ran_once_flag | Flag for the rate limit retry. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.Folders.ChildFolderCount | Number | The number of child folders. |
| MSGraphMail.Folders.DisplayName | String | The folder display name. |
| MSGraphMail.Folders.ID | String | The folder ID. |
| MSGraphMail.Folders.ParentFolderID | String | The parent folder ID. |
| MSGraphMail.Folders.TotalItemCount | Number | The total number of email messages in the folder. |
| MSGraphMail.Folders.UnreadItemCount | Number | The number of unread email messages in the folder. |
msgraph-mail-list-rules
List email rules for a user’s mailbox using Microsoft Graph API.
Base Command
msgraph-mail-list-rules
Input
| Argument Name | Description | Required |
|---|---|---|
| limit | Maximum number of results to return. Default is 50. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.Rule.conditions | Unknown | Conditions that when fulfilled, will trigger the corresponding actions for that rule. |
| MSGraphMail.Rule.actions | Unknown | Actions to be taken on a message when the corresponding conditions are fulfilled. |
| MSGraphMail.Rule.displayName | String | The display name of the rule. |
| MSGraphMail.Rule.exceptions | Unknown | Exception conditions for the rule. |
| MSGraphMail.Rule.hasError | Boolean | Indicates whether the rule is in an error condition. |
| MSGraphMail.Rule.id | String | The ID of the rule. |
| MSGraphMail.Rule.isEnabled | Boolean | Indicates whether the rule is enabled to be applied to messages. |
| MSGraphMail.Rule.isReadOnly | Boolean | Indicates if the rule is read-only and cannot be modified or deleted by the rules REST API. |
| MSGraphMail.Rule.sequence | Number | Indicates the order in which the rule is executed, among other rules. |
msgraph-mail-get-rule
Get details of a specific email rule by ID for a user’s mailbox using Microsoft Graph API.
Base Command
msgraph-mail-get-rule
Input
| Argument Name | Description | Required |
|---|---|---|
| rule_id | The ID of the rule to retrieve. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| MSGraphMail.Rule.conditions | Unknown | Conditions that when fulfilled, will trigger the corresponding actions for that rule. |
| MSGraphMail.Rule.actions | Unknown | Actions to be taken on a message when the corresponding conditions are fulfilled. |
| MSGraphMail.Rule.displayName | String | The display name of the rule. |
| MSGraphMail.Rule.exceptions | Unknown | Exception conditions for the rule. |
| MSGraphMail.Rule.hasError | Boolean | Indicates whether the rule is in an error condition. |
| MSGraphMail.Rule.id | String | The ID of the rule. |
| MSGraphMail.Rule.isEnabled | Boolean | Indicates whether the rule is enabled to be applied to messages. |
| MSGraphMail.Rule.isReadOnly | Boolean | Indicates if the rule is read-only and cannot be modified or deleted by the rules REST API. |
| MSGraphMail.Rule.sequence | Number | Indicates the order in which the rule is executed, among other rules. |
msgraph-mail-delete-rule
Delete a specific email rule by ID for a user’s mailbox using Microsoft Graph API.
Base Command
msgraph-mail-delete-rule
Input
| Argument Name | Description | Required |
|---|---|---|
| rule_id | The ID of the rule to delete. | Required |
Context Output
There is no context output for this command.
Troubleshooting
In case of a hash verification error:
- Use the Oproxy flow to generate a new pair of credentials. This is crucial as it ensures that any issues related to authentication can be mitigated with fresh credentials.
- Execute the command !msgraph-mail-auth-reset. This command resets the authentication mechanism, allowing for the new credentials to be accepted.
- Insert the newly created credentials into the original instance where the error occurred. Make sure the credentials are entered correctly to avoid further errors.
- After updating the credentials, test the integration.
<~PLATFORM>
License Requirements
The following configuration parameters require one of these licenses: Cortex XSIAM or Agentix:
- Fetch incidents
</~PLATFORM>
Configuration parameters
creds_auth_id—creds_refresh_token—creds_enc_key—auth_id— ID or Client IDrefresh_token— Token or Tenant IDenc_key— Key or Client Secretcreds_certificate— Certificate Thumbprint (optional for self-deployed Azure app)certificate_thumbprint— Certificate Thumbprint (optional for self-deployed Azure app)private_key— Private Keycreds_auth_code—auth_code— Authorization code (required for self-deployed Azure app)redirect_uri— Application redirect URI (required for self-deployed Azure app)self_deployed— Use a self-deployed Azure applicationuse_managed_identities— Use Azure Managed Identitiesmanaged_identities_client_id—isFetch— Fetch incidentsmailbox_to_fetch— Email address to associate for this integration.folder_to_fetch— Name of the folder from which to fetch incidents (supports Folder ID and sub-folders e.g., Inbox/Phishing)first_fetch— First fetch timestamp (<number> <time unit>, e.g., 12 hours, 7 days)fetch_limit— Maximum number of emails to pull per fetchincidentType— Incident typedisplay_full_email_body— Display full email bodyfetch_html_formatting— Fetch emails in HTML formatmark_fetched_read— Mark fetched emails as readincidentFetchInterval— Incidents Fetch Intervalinsecure— Trust any certificate (not secure)proxy— Use system proxy settingslegacy_name— Use legacy attachment name
Commands (21)
-
msgraph-email-security-send-email-to-recipients-office-365-quick-actionSends an email using Microsoft Graph.
-
msgraph-mail-auth-resetRun this command if for some reason you need to rerun the authentication process.
-
msgraph-mail-create-draftCreates a draft message in the specified user's mailbox.
-
msgraph-mail-create-folderCreates a new folder under the specified folder (parent).
-
msgraph-mail-delete-ruleDelete a specific email rule by ID for a user's mailbox using Microsoft Graph API.
-
msgraph-mail-generate-login-urlGenerate the login url used for Authorization code flow.
-
msgraph-mail-get-attachmentGets an attachment from the email.
-
msgraph-mail-get-email-as-emlRetrieves an email message by message ID and uploads the content as an EML file.
-
msgraph-mail-get-ruleGet details of a specific email rule by ID for a user's mailbox using Microsoft Graph API.
-
msgraph-mail-list-attachmentsLists all attachments of an email.
-
msgraph-mail-list-child-foldersReturns the folder list under the specified folder.
-
msgraph-mail-list-emailsGets the properties of returned emails. Typically shows partial results, use the "page_size" and "pages_to_pull" arguments to get all results. This command lists emails only from the mailbox specified in the integration configuration.
-
msgraph-mail-list-foldersReturns the mail folder list directly under the root folder.
-
msgraph-mail-list-rulesList email rules for a user's mailbox using Microsoft Graph API.
-
msgraph-mail-move-emailMove a message to another folder. This operation creates a new copy of the message in the destination folder and deletes the original message. As a result, the message ID changes.
-
msgraph-mail-reply-toThe replies to the recipients of a message.
-
msgraph-mail-send-draftSends a draft email using Microsoft Graph.
-
msgraph-mail-testTests connectivity of the email.
-
msgraph-update-email-statusUpdate the status of an email to read / unread.
-
reply-mailReplies to an email using Graph Mail Single User.
-
send-mailSends an email using Microsoft Graph.
import json import demistomock as demisto # noqa: F401 import urllib3 from CommonServerPython import * # noqa: F401 from MicrosoftGraphMailApiModule import * # noqa: E402 # Disable insecure warnings urllib3.disable_warnings() DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ" # Commands that require a configured mailbox (mailbox_to_fetch). # Because this integration uses delegated permissions against a single mailbox, # these commands cannot run without it. COMMANDS_REQUIRING_MAILBOX = { "fetch-incidents", "msgraph-mail-create-folder", "msgraph-mail-delete-rule", "msgraph-mail-get-attachment", "msgraph-mail-get-email-as-eml", "msgraph-mail-get-rule", "msgraph-mail-list-attachments", "msgraph-mail-list-child-folders", "msgraph-mail-list-emails", "msgraph-mail-list-folders", "msgraph-mail-move-email", } class MsGraphListenerClient(MsGraphMailBaseClient): """ MsGraphListenerClient enables authorized access to a user's Office 365 mail data in a personal account. """ def __init__(self, **kwargs): super().__init__(grant_type=AUTHORIZATION_CODE, **kwargs) @staticmethod def _get_next_run_time(fetched_emails, start_time): """ Returns received time of last email if exist, else utc time that was passed as start_time. The elements in fetched emails are ordered by modified time in ascending order, meaning the last element has the latest received time. :type fetched_emails: ``list`` :param fetched_emails: List of fetched emails :type start_time: ``str`` :param start_time: utc string of format Y-m-dTH:M:SZ :return: Returns str date of format Y-m-dTH:M:SZ :rtype: `str` """ return fetched_emails[-1].get("receivedDateTime") if fetched_emails else start_time @logger def fetch_incidents(self, last_run): """ Fetches emails from office 365 mailbox and creates incidents of parsed emails. :type last_run: ``dict`` :param last_run: Previous fetch run data that holds the fetch time in utc Y-m-dTH:M:SZ format, ids of fetched emails, id and path of folder to fetch incidents from :return: Next run data and parsed fetched incidents :rtype: ``dict`` and ``list`` """ last_fetch = last_run.get("LAST_RUN_TIME") exclude_ids = last_run.get("LAST_RUN_IDS", []) last_run_folder_path = last_run.get("LAST_RUN_FOLDER_PATH") folder_path_changed = last_run_folder_path != self._folder_to_fetch demisto.debug("MicrosoftGraphMail - Start fetching") demisto.debug(f"MicrosoftGraphMail - Last run: {json.dumps(last_run)}") if folder_path_changed: # detected folder path change, get new folder id folder_id = self._get_folder_by_path( self._mailbox_to_fetch, self._folder_to_fetch, overwrite_rate_limit_retry=True ).get("id") demisto.info("detected file path change, ignored last run.") else: # LAST_RUN_FOLDER_ID is stored in order to avoid calling _get_folder_by_path method in each fetch folder_id = last_run.get("LAST_RUN_FOLDER_ID") if not last_fetch or folder_path_changed: # initialized fetch last_fetch, _ = parse_date_range(self._first_fetch_interval, date_format=DATE_FORMAT, utc=True) demisto.info(f"initialize fetch and pull emails from date :{last_fetch}") fetched_emails, exclude_ids = self._fetch_last_emails(folder_id=folder_id, last_fetch=last_fetch, exclude_ids=exclude_ids) incidents = [self._parse_email_as_incident(email, True) for email in fetched_emails] next_run_time = self._get_next_run_time(fetched_emails, last_fetch) next_run = { "LAST_RUN_TIME": next_run_time, "LAST_RUN_IDS": exclude_ids, "LAST_RUN_FOLDER_ID": folder_id, "LAST_RUN_FOLDER_PATH": self._folder_to_fetch, } demisto.debug(f"MicrosoftGraphMail - Next run after incidents fetching: {json.dumps(next_run)}") demisto.debug(f"MicrosoftGraphMail - Number of incidents before filtering: {len(fetched_emails)}") demisto.debug(f"MicrosoftGraphMail - Number of incidents after filtering: {len(incidents)}") demisto.debug(f"MicrosoftGraphMail - Number of incidents skipped: {len(fetched_emails)-len(incidents)}") """ The below pop is here to maintain parity between this (single-user) version of the graph mail integration and the application-permission version. It is output by the ApiModule but does not provide any functionaltiy and consideration should be given in the future to either removing it's addition in the Api module. """ for incident in incidents: # remove the ID from the incidents, they are used only for look-back. incident.pop("ID", None) demisto.info(f"fetched {len(incidents)} incidents") demisto.debug(f"{next_run=}") return next_run, incidents def main(): # pragma: no cover """COMMANDS MANAGER / SWITCH PANEL""" params = demisto.params() # params related to common instance configuration base_url = "https://graph.microsoft.com/v1.0/" use_ssl = not params.get("insecure", False) proxy = params.get("proxy", False) ok_codes = (200, 201, 202) refresh_token = params.get("creds_refresh_token", {}).get("password") or params.get("refresh_token", "") auth_and_token_url = params.get("creds_auth_id", {}).get("password") or params.get("auth_id", "") enc_key = params.get("creds_enc_key", {}).get("password") or params.get("enc_key", "") certificate_thumbprint = params.get("creds_certificate", {}).get("identifier") or params.get("certificate_thumbprint") private_key = replace_spaces_in_credential(params.get("creds_certificate", {}).get("password")) or params.get("private_key") auth_code = params.get("creds_auth_code", {}).get("password") or params.get("auth_code", "") app_name = "ms-graph-mail-listener" managed_identities_client_id = get_azure_managed_identities_client_id(params) self_deployed = params.get("self_deployed", False) or managed_identities_client_id is not None if not managed_identities_client_id: if not self_deployed and not enc_key: raise DemistoException( "Key must be provided. For further information see " "https://xsoar.pan.dev/docs/reference/articles/microsoft-integrations---authentication" ) elif not enc_key and not (certificate_thumbprint and private_key): raise DemistoException("Key or Certificate Thumbprint and Private Key must be provided.") # params related to mailbox to fetch incidents mailbox_to_fetch = params.get("mailbox_to_fetch", "") folder_to_fetch = params.get("folder_to_fetch", "Inbox") first_fetch_interval = params.get("first_fetch", "15 minutes") emails_fetch_limit = int(params.get("fetch_limit", "50")) display_full_email_body = argToBoolean(params.get("display_full_email_body", "false")) mark_fetched_read = argToBoolean(params.get("mark_fetched_read", "false")) fetch_html_formatting = argToBoolean(params.get("fetch_html_formatting", "false")) legacy_name = argToBoolean(params.get("legacy_name", False)) # params related to self deployed tenant_id = refresh_token if self_deployed else "" # params related to oproxy # In case the script is running for the first time, refresh token is retrieved from integration parameters, # in other case it's retrieved from integration context. refresh_token = get_integration_context().get("current_refresh_token") or refresh_token client = MsGraphListenerClient( self_deployed=self_deployed, tenant_id=tenant_id, auth_id=auth_and_token_url, enc_key=enc_key, app_name=app_name, base_url=base_url, verify=use_ssl, proxy=proxy, ok_codes=ok_codes, mailbox_to_fetch=mailbox_to_fetch, folder_to_fetch=folder_to_fetch, first_fetch_interval=first_fetch_interval, emails_fetch_limit=emails_fetch_limit, fetch_html_formatting=fetch_html_formatting, legacy_name=legacy_name, refresh_token=refresh_token, auth_code=auth_code, private_key=private_key, display_full_email_body=display_full_email_body, mark_fetched_read=mark_fetched_read, redirect_uri=params.get("redirect_uri", ""), certificate_thumbprint=certificate_thumbprint, managed_identities_client_id=managed_identities_client_id, ) try: args = demisto.args() command = demisto.command() LOG(f"Command being called is {command}") if command in COMMANDS_REQUIRING_MAILBOX and not mailbox_to_fetch: raise DemistoException( 'The "Email address to associate for this integration" parameter is required for ' f'the "{command}" command. Please configure it on the integration instance.' ) if command == "test-module": if managed_identities_client_id: return_results(client.test_connection()) else: # cannot use test module due to the lack of ability to set refresh token to integration context raise Exception("Please use !msgraph-mail-test instead") if command == "msgraph-mail-test": client.test_connection() return_results(CommandResults(readable_output="```✅ Success!```")) if command == "msgraph-mail-auth-reset": return_results(reset_auth()) if command == "fetch-incidents": next_run, incidents = client.fetch_incidents(demisto.getLastRun()) demisto.setLastRun(next_run) demisto.incidents(incidents) elif command == "msgraph-mail-list-emails": return_results(list_mails_command(client, args)) elif command == "msgraph-mail-create-draft": return_results(create_draft_command(client, args)) elif command == "msgraph-mail-reply-to": return_results(reply_to_command(client, args)) elif command == "msgraph-mail-list-attachments": return_results(list_attachments_command(client, args)) elif command == "msgraph-mail-get-attachment": return_results(get_attachment_command(client, args)) elif command == "msgraph-mail-create-folder": return_results(create_folder_command(client, args)) elif command == "msgraph-mail-get-email-as-eml": return_results(get_email_as_eml_command(client, args)) elif command == "msgraph-mail-move-email": return_results(move_email_command(client, args)) elif command == "msgraph-mail-list-folders": return_results(list_folders_command(client, args)) elif command == "msgraph-mail-list-child-folders": return_results(list_child_folders_command(client, args)) elif command == "msgraph-mail-send-draft": return_results(send_draft_command(client, args)) # pylint: disable=E1123 elif command == "msgraph-update-email-status": return_results(update_email_status_command(client, args)) elif command == "reply-mail": return_results(reply_email_command(client, args)) elif command == "send-mail" or command == "msgraph-email-security-send-email-to-recipients-office-365-quick-action": return_results(send_email_command(client, args)) elif command == "msgraph-mail-generate-login-url": return_results(generate_login_url(client)) elif command in ["msgraph-mail-get-rule", "msgraph-mail-list-rules"]: return_results(list_rule_action_command(client, args)) elif command == "msgraph-mail-delete-rule": return_results(delete_rule_command(client, args)) except Exception as e: return_error(str(e)) if __name__ in ("__main__", "__builtin__", "builtins"): main()