AutomationFlowsEmail & Gmail › Email Handler New

Email Handler New

email-handler-new. Uses gmail, gmailTrigger, postgres. Webhook trigger; 10 nodes.

Webhook trigger★★★★☆ complexity10 nodesGmailGmail TriggerPostgres
Email & Gmail Trigger: Webhook Nodes: 10 Complexity: ★★★★☆ Added:

This workflow follows the Gmail → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.

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
{
  "active": true,
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Get a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Update rows in a table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a message": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update rows in a table": {
      "main": [
        [
          {
            "node": "Select rows from a table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select rows from a table": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2025-11-23T09:50:59.926Z",
  "id": "AykqUj5CBOSzPO5I",
  "isArchived": false,
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "email-handler-new",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "send-email",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "3fe03690-4288-4ce1-b597-08a02fa1e460",
      "name": "Webhook"
    },
    {
      "parameters": {
        "sendTo": "={{ $json.body.to }}",
        "subject": "={{ $json.body.subject }}",
        "message": "={{ $json.body.html_body }}\n<span style=\"font-size:1px; color:#f5f5f5; line-height:0; display:block;\">\n  RFRNO:##{{ $json.body.tracking_info.tracking_id }}##\n</span>",
        "options": {
          "appendAttribution": false,
          "bccList": "={{ $json.body.bcc }}",
          "ccList": "={{ $json.body.cc }}",
          "senderName": "={{ $json.body.sender_name }}"
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        208,
        0
      ],
      "id": "87e2f6fa-4938-40a1-b53b-80cc6dac7123",
      "name": "Send a message",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        400,
        0
      ],
      "id": "289bf885-3616-4ac6-b3a2-840cc6fba1a8",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 5,
              "unit": "minutes"
            }
          ]
        },
        "simple": false,
        "filters": {},
        "options": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        272
      ],
      "id": "b1c3471e-ab94-4529-817c-6079430cb785",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "aa28b95b-5179-4887-8a0b-30206041dc57",
              "leftValue": "={{ $json.html }}",
              "rightValue": "RFRNO:",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        480,
        272
      ],
      "id": "5b61b259-2303-41a9-9d61-b44e2f9f4376",
      "name": "If"
    },
    {
      "parameters": {
        "operation": "update",
        "schema": {
          "__rl": true,
          "value": "public",
          "mode": "list",
          "cachedResultName": "public"
        },
        "table": {
          "__rl": true,
          "value": "campaign_sends",
          "mode": "list",
          "cachedResultName": "campaign_sends"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "is_replied": true,
            "tracking_id": "={{ $json.extractedText }}",
            "replied_at": "={{ $now }}"
          },
          "matchingColumns": [
            "tracking_id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "campaign_id",
              "displayName": "campaign_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "contact_id",
              "displayName": "contact_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "template_id",
              "displayName": "template_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "sequence_index",
              "displayName": "sequence_index",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "scheduled_date",
              "displayName": "scheduled_date",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "sent_date",
              "displayName": "sent_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "rendered_subject",
              "displayName": "rendered_subject",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "rendered_body_html",
              "displayName": "rendered_body_html",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "rendered_body_text",
              "displayName": "rendered_body_text",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "is_sent",
              "displayName": "is_sent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "is_opened",
              "displayName": "is_opened",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "is_clicked",
              "displayName": "is_clicked",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "is_replied",
              "displayName": "is_replied",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true
            },
            {
              "id": "is_failed",
              "displayName": "is_failed",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "is_cancelled",
              "displayName": "is_cancelled",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "opened_at",
              "displayName": "opened_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "clicked_at",
              "displayName": "clicked_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "replied_at",
              "displayName": "replied_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true
            },
            {
              "id": "failed_at",
              "displayName": "failed_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "failure_reason",
              "displayName": "failure_reason",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "tracking_pixel_url",
              "displayName": "tracking_pixel_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "unsubscribe_url",
              "displayName": "unsubscribe_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "updated_at",
              "displayName": "updated_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "tracking_id",
              "displayName": "tracking_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1024,
        192
      ],
      "id": "49dadd35-0a63-42d3-91d9-0223f13d1952",
      "name": "Update rows in a table",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Uzun metnin geldi\u011fi alan\u0131n ad\u0131 (\u00f6r: \"text\")\nconst fullText = $input.first().json.html || '';\n\n// Regex ile ilk ##...## aras\u0131n\u0131 yakala\nconst match = fullText.match(/##(.*?)##/s);\n\n// Elde edilen metin (yoksa bo\u015f string d\u00f6ner)\nconst extractedText = match ? match[1] : '';\n\n// Sadece string d\u00f6nen basit bir json d\u00f6nd\u00fcr\u00fcyoruz\nreturn [\n  {\n    json: {\n      extractedText,  // \u00d6rn: \"ALINACAK MET\u0130N\"\n    },\n  },\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        192
      ],
      "id": "385ee88b-10b3-4e8f-91bc-3d259c059ef3",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "operation": "get",
        "messageId": "={{ $json.threadId }}",
        "simple": false,
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        256,
        272
      ],
      "id": "c34bd185-dd74-40f1-91fc-c38f8fc35a4b",
      "name": "Get a message",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "select",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "email_campaigns",
          "mode": "list",
          "cachedResultName": "email_campaigns"
        },
        "limit": 1,
        "where": {
          "values": [
            {
              "column": "status",
              "value": "active"
            },
            {
              "column": "id",
              "value": "={{ $json.campaign_id }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1248,
        192
      ],
      "id": "6fb87f45-3ab3-43bc-a291-3ae62ad6ba00",
      "name": "Select rows from a table",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $json.reply_notification_email }}",
        "subject": "=Otomasyon ile g\u00f6nderilmi\u015f bir epostan\u0131za yan\u0131t geldi! (CID: {{ $json.id }})",
        "message": "=<!DOCTYPE html>\n<html lang=\"tr\">\n<head>\n  <meta charset=\"UTF-8\" />\n  <title>Cerilas Email Otomasyonu - Yan\u0131t Bildirimi</title>\n  <style>\n    body {\n      font-family: Arial, sans-serif;\n      font-size: 14px;\n      color: #333333;\n      background-color: #f5f5f5;\n      margin: 0;\n      padding: 20px;\n    }\n    .container {\n      max-width: 600px;\n      margin: 0 auto;\n      background-color: #ffffff;\n      border-radius: 6px;\n      border: 1px solid #e0e0e0;\n      padding: 20px 24px;\n    }\n    h1 {\n      font-size: 18px;\n      margin-top: 0;\n      color: #222222;\n    }\n    p {\n      margin: 8px 0;\n      line-height: 1.5;\n    }\n    .label {\n      font-weight: bold;\n    }\n    .value {\n      font-family: \"Courier New\", monospace;\n    }\n    .footer {\n      margin-top: 20px;\n      padding-top: 10px;\n      border-top: 1px solid #eeeeee;\n      font-size: 12px;\n      color: #777777;\n    }\n    .kampanya-id {\n      font-size: 13px;\n      color: #555555;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"container\">\n    <h1>Otomasyon Yan\u0131t Bildirimi</h1>\n\n    <p class=\"kampanya-id\">\n      Otomasyon ile g\u00f6nderilmi\u015f bir epostan\u0131za yan\u0131t geldi! \n      (Kampanya ID: <span class=\"value\">{{ $json.id }}</span>)\n    </p>\n\n    <p>\n      <span class=\"label\">Yan\u0131t\u0131 g\u00f6nderen e-posta:</span><br />\n      <span class=\"value\">{{ $('Get a message').item.json.to.value[0].address }}</span>\n    </p>\n\n    <p>\n      <span class=\"label\">Konu:</span><br />\n      <span class=\"value\">{{ $('Get a message').item.json.subject }}</span>\n    </p>\n\n    <p>\n      <span class=\"label\">\u0130\u00e7erik:</span><br />\n      <span class=\"value\">{{ $('Gmail Trigger').item.json.text }}</span>\n    </p>\n\n    <p>\n      <span class=\"label\">Takip numaras\u0131:</span><br />\n      <span class=\"value\">{{ $('Code in JavaScript').item.json.extractedText }}</span>\n    </p>\n\n    <div class=\"footer\">\n      Cerilas Email Otomasyonu\n    </div>\n  </div>\n</body>\n</html>",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1456,
        192
      ],
      "id": "d3b350f6-e337-4c00-8041-55c419df1853",
      "name": "Send a message1",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "origin": "n8n",
  "repo": {
    "owner": "octaworksofficial",
    "name": "n8n"
  },
  "settings": {
    "executionOrder": "v1"
  },
  "shared": [
    {
      "createdAt": "2025-11-23T09:50:59.930Z",
      "updatedAt": "2025-11-23T09:50:59.930Z",
      "role": "workflow:owner",
      "workflowId": "AykqUj5CBOSzPO5I",
      "projectId": "1jTilK588wM2KuJy"
    }
  ],
  "staticData": {
    "node:Gmail Trigger": {
      "Gmail Trigger": {
        "lastTimeChecked": 1764893957,
        "possibleDuplicates": [
          "19aebe0d393bbcba",
          "19aeab3363c4fc8d"
        ]
      }
    }
  },
  "tags": [],
  "triggerCount": 2,
  "updatedAt": "2025-12-02T12:52:18.000Z",
  "versionId": "10717484-e0ed-4f26-9101-672d75a895d3"
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

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

About this workflow

email-handler-new. Uses gmail, gmailTrigger, postgres. Webhook trigger; 10 nodes.

Source: https://github.com/octaworksofficial/n8n/blob/20a248338297da94c67a12b0db3035f88d91a82f/AykqUj5CBOSzPO5I.json — original creator credit. Request a take-down →

More Email & Gmail workflows → · Browse all categories →

Related workflows

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

Email & Gmail

Suspicious_login_detection. Uses postgres, httpRequest, noOp, html. Webhook trigger; 43 nodes.

Postgres, HTTP Request, Gmail +1
Email & Gmail

This n8n workflow is designed for security monitoring and incident response when suspicious login events are detected. It can be initiated either manually from within the n8n UI for testing or automat

Postgres, HTTP Request, Gmail +1
Email & Gmail

Workflow1-2-3. Uses httpRequest, gmail, telegram, postgres. Webhook trigger; 34 nodes.

HTTP Request, Gmail, Telegram +2
Email & Gmail

This n8n template automates responses to customer inquiries about DHL shipment status, handling requests from both web forms and emails. Automate Customer Support: Provide 24/7 instant answers to the

Gmail Trigger, HTTP Request, Gmail
Email & Gmail

BPC GetData. Uses gmailTrigger, gmail, postgres. Event-driven trigger; 4 nodes.

Gmail Trigger, Gmail, Postgres