AutomationFlowsWeb Scraping › Secure Email Search with Webhook

Secure Email Search with Webhook

Original n8n title: Email Search

email_search. Uses httpRequest. Webhook trigger; 5 nodes.

Webhook trigger★★★★☆ complexity5 nodesHTTP Request
Web Scraping Trigger: Webhook Nodes: 5 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "email_search",
  "nodes": [
    {
      "id": "bbbbbbbb-0000-0000-0000-000000000001",
      "name": "Receive Request",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        260,
        200
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "email-search",
        "responseMode": "responseNode",
        "authentication": "headerAuth",
        "options": {}
      }
    },
    {
      "id": "bbbbbbbb-0000-0000-0000-000000000005",
      "name": "Enforce Mailbox Allowlist",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        380,
        200
      ],
      "parameters": {
        "jsCode": "const body = $input.first().json.body || {};\nconst mailbox = (body.user_mailbox || '').toLowerCase();\nconst allowed = (body.allowed_mailboxes || []).map(m => String(m).toLowerCase());\nif (!mailbox) {\n  throw new Error('user_mailbox is required');\n}\nif (allowed.length === 0 || !allowed.includes(mailbox)) {\n  throw new Error('mailbox_not_in_allowlist: ' + mailbox);\n}\nreturn [{ json: $input.first().json }];"
      }
    },
    {
      "id": "bbbbbbbb-0000-0000-0000-000000000002",
      "name": "Graph Mail Search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        500,
        200
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ 'https://graph.microsoft.com/v1.0/users/' + encodeURIComponent($json.body.user_mailbox || '') + '/messages?$search=' + encodeURIComponent('\"' + ($json.body.query || '') + '\"') + '&$top=25' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ 'Bearer ' + $json.body.access_token }}"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "bbbbbbbb-0000-0000-0000-000000000003",
      "name": "Normalize Evidence",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        740,
        200
      ],
      "parameters": {
        "jsCode": "const body = $input.first().json;\nconst values = Array.isArray(body.value) ? body.value : [];\nconst projectCode = $json.body?.project_code || null;\nconst allowedMailboxes = $json.body?.allowed_mailboxes || [];\n\nconst evidence = values.map((msg, index) => {\n  const sender = msg.sender?.emailAddress?.address || '';\n  const recipients = (msg.toRecipients || []).map(r => r.emailAddress?.address).filter(Boolean);\n  const mailbox = $json.body?.user_mailbox || '';\n  \n  const excerpt = (msg.bodyPreview || msg.subject || '').toString().substring(0, 500);\n  let hash;\n  try {\n    const crypto = require('crypto');\n    hash = crypto.createHash('sha256').update(msg.id + (msg.internetMessageId || '')).digest('hex');\n  } catch (e) {\n    hash = 'eml-' + (msg.id || index) + '-' + (msg.receivedDateTime || 'unknown');\n  }\n  \n  return {\n    evidence_id: 'eml-' + (msg.id || index),\n    source_type: 'email',\n    source_uri: 'https://graph.microsoft.com/v1.0/users/' + encodeURIComponent(mailbox) + '/messages/' + (msg.id || ''),\n    title: msg.subject || 'No subject',\n    project_code: projectCode,\n    contract_no: $json.body?.contract_no || null,\n    revision: null,\n    timestamp: msg.receivedDateTime || null,\n    excerpt: excerpt,\n    hash_sha256: hash,\n    confidence: 'medium',\n    tags: ['email', 'timeline'],\n    metadata: {\n      sender: sender,\n      recipients: recipients,\n      mailbox: mailbox,\n      has_attachments: msg.hasAttachments || false,\n      message_id: msg.internetMessageId || null\n    }\n  };\n});\n\nreturn [{ json: { evidence: evidence } }];"
      }
    },
    {
      "id": "bbbbbbbb-0000-0000-0000-000000000004",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.2,
      "position": [
        980,
        200
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {
          "responseCode": 200
        }
      }
    }
  ],
  "connections": {
    "Receive Request": {
      "main": [
        [
          {
            "node": "Enforce Mailbox Allowlist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enforce Mailbox Allowlist": {
      "main": [
        [
          {
            "node": "Graph Mail Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Graph Mail Search": {
      "main": [
        [
          {
            "node": "Normalize Evidence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Evidence": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

email_search. Uses httpRequest. Webhook trigger; 5 nodes.

Source: https://github.com/chyones/DecisionCenter/blob/ba4fde6505a6d15d4adb559f060508c2437b27be/n8n/email_search.json — original creator credit. Request a take-down →

More Web Scraping workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Web Scraping

This n8n template provides enterprise-level version control for your workflows using GitHub integration. Stop losing hours to broken workflows and manual exports – get proper commit history, visual di

n8n, Execute Workflow Trigger, HTTP Request +1
Web Scraping

This flow creates dummy files for every item added in your *Arrs (Radarr/Sonarr) with the tag .

HTTP Request, Ssh
Web Scraping

This workflow acts as a central API gateway for all technical indicator agents in the Binance Spot Market Quant AI system. It listens for incoming webhook requests and dynamically routes them to the c

HTTP Request
Web Scraping

Sign PDF documents with legally-compliant digital signatures using X.509 certificates. Supports multiple PAdES signature levels (B, T, LT, LTA) with optional visible stamps.

Execute Command, HTTP Request, Read Write File +1
Web Scraping

📡 This workflow serves as the central Alpha Vantage API fetcher for Tesla trading indicators, delivering cleaned 20-point JSON outputs for three timeframes: , , and . It is required by the following a

HTTP Request