Analyze & Sort Suspicious Email Contents with ChatGPT n8n Workflow Template

n8n workflow template · 19 nodes · Gmail

Analyze & Sort Suspicious Email Contents with ChatGPT is a free n8n workflow template that starts from the Gmail Trigger node and works with Gmail, Microsoft Outlook, OpenAI and Jira Software. It has 19 nodes, 1 of them AI nodes (OpenAI). The notes inside the workflow say: “This section of the workflow connects to a Gmail account using the Gmail Trigger node, capturing incoming emails in real-time, with checks performed every minute.” To run it, you add your own credentials for Gmail OAuth2, HTTP Basic Auth, Jira Software Cloud API, Microsoft Outlook OAuth2 and OpenAI API.

At a glance

Trigger
Gmail Trigger (Gmail Trigger)
Nodes
19
Apps
Gmail, Microsoft Outlook, OpenAI and Jira Software
AI nodes
1
Credentials
5 types
Category
IT, security and DevOps

Apps and integrations

  • Gmail
  • Microsoft Outlook
  • OpenAI
  • Jira Software

Node types used

  • Gmail Trigger
  • Microsoft Outlook Trigger
  • HTTP Request
  • Edit Fields (Set)
  • Code
  • OpenAI
  • Jira Software
  • Convert to File
  • If

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Gmail Integration and Data Extraction

This section of the workflow connects to a Gmail account using the Gmail Trigger node, capturing incoming emails in real-time, with checks performed every minute. Once an email is detected, its key components—such as the subject, recipient, body, and headers—are extracted and assigned to variables using the Set Gmail Variables node. These variables are structured for subsequent analysis and processing in later steps.

Microsoft Outlook Integration and Email Header Processing

This section enables the integration of Microsoft Outlook to monitor and capture incoming emails. The Microsoft Outlook Trigger node checks for new messages every minute. Once an email is detected, the Retrieve Headers of Email node fetches detailed header and body content via the Microsoft Graph API. The Format Headers node organizes the email headers into a structured format using a JavaScript function, ensuring clarity and readiness for further processing. Finally, the Set Outlook Variables node extracts and assigns key details—such as the email subject, recipient, body, and formatted headers—to variables for use in subsequent workflow steps. This section is essential for processing Outlook emails and preparing them for analysis and reporting.

Email Body Conversion

This section processes the email body into both text and visual formats for detailed analysis and reporting. The Set Email Variables node organizes the email's data, including its HTML body and text content, to prepare it for further steps. The Convert Email Body to File node creates a.txt file containing the plain text version of the email body, useful for documentation or further analysis.

Email Body Screenshot Creation

The Screenshot HTML node sends the email's HTML body to the hcti.io API, generating a screenshot that visually represents the email's layout. The Retrieve Screenshot node then fetches this image, making it available for attachment or review in subsequent steps. This dual-format processing ensures both clarity and flexibility in email analysis workflows.

AI-Powered Email Analysis and Threat Detection

This section leverages ChatGPT for advanced email content and header analysis to determine potential phishing threats. The Analyze Email with ChatGPT node processes the email's HTML body and headers, generating a detailed JSON response that categorizes the email as malicious or benign. The response includes a verbose explanation, formatted for Jira, outlining the reasons for the classification. The Check if Malicious node evaluates the AI output to determine the next steps based on the email's threat status. If flagged as malicious, subsequent actions like reporting and ticket creation are triggered. This section ensures precise, AI-driven analysis to enhance email security workflows.

Automated Jira Ticket Creation and Email Attachment

This section streamlines the process of logging phishing email reports in Jira, complete with detailed analysis and attachments. The workflow creates two distinct Jira tickets depending on the AI classification of the email

  1. Potentially Malicious: The Create Potentially Malicious Ticket node generates a ticket if the email is flagged as a phishing attempt, including a summary of ChatGPT's analysis and the email’s details.
  2. Potentially Benign: If the email is classified as safe, the Create Potentially Benign Ticket node logs a ticket with similar details but under a non-malicious category.

The Set Jira ID node ensures the generated ticket's ID is tracked for subsequent operations. Attachments are handled efficiently

  • Rename Screenshot prepares the email screenshot for upload.
  • Upload Screenshot of Email to Jira adds the screenshot to the Jira ticket for visual context.
  • Rename Email Body Screenshot and Upload Email Body to Jira manage the attachment of the email's text body as a.txt file.

This section enhances reporting by automating ticket creation, ensuring all relevant email data is readily available for review by security teams.

Nodes in this workflow

The 19 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Gmail Trigger (Gmail Trigger)
  2. Microsoft Outlook Trigger (Microsoft Outlook Trigger)
  3. Screenshot HTML (HTTP Request)
  4. Retrieve Screenshot (HTTP Request)
  5. Set Outlook Variables (Edit Fields (Set))
  6. Set Gmail Variables (Edit Fields (Set))
  7. Retrieve Headers of Email (HTTP Request)
  8. Format Headers (Code)
  9. Analyze Email with ChatGPT (OpenAI)
  10. Create Potentially Malicious Ticket (Jira Software)
  11. Create Potentially Benign Ticket (Jira Software)
  12. Rename Screenshot (Code)
  13. Set Jira ID (Edit Fields (Set))
  14. Upload Screenshot of Email to Jira (Jira Software)
  15. Upload Email Body to Jira (Jira Software)
  16. Convert Email Body to File (Convert to File)
  17. Set Email Variables (Edit Fields (Set))
  18. Rename Email Body Screenshot (Code)
  19. Check if Malicious (If)

Credentials you need

  • Gmail OAuth2 – used by Gmail Trigger
  • HTTP Basic Auth – used by Retrieve Screenshot and Screenshot HTML
  • Jira Software Cloud API – used by Create Potentially Benign Ticket, Create Potentially Malicious Ticket, Upload Email Body to Jira and Upload Screenshot of Email to Jira
  • Microsoft Outlook OAuth2 – used by Microsoft Outlook Trigger and Retrieve Headers of Email
  • OpenAI API – used by Analyze Email with ChatGPT

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us