AutomationFlowsData & Sheets › Job.3_email_application_linker

Job.3_email_application_linker

job.3_email_application_linker. Uses postgres. Scheduled trigger; 11 nodes.

Cron / scheduled trigger★★★★☆ complexity11 nodesPostgres
Data & Sheets Trigger: Cron / scheduled Nodes: 11 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": "job.3_email_application_linker",
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT\n    e.email_id,\n    e.sender,\n    e.subject,\n    e.received_at\nFROM emails e\nWHERE EXISTS (\n    SELECT 1\n    FROM events er\n    WHERE er.event_type = 'EMAIL_RECEIVED'\n      AND er.payload->>'email_id' = e.email_id::text\n)\nAND EXISTS (\n    SELECT 1\n    FROM events ec\n    WHERE ec.event_type = 'EMAIL_CLASSIFIED'\n      AND ec.payload->>'email_id' = e.email_id::text\n      AND ec.payload->>'category' != 'NON_JOB'\n)\nAND NOT EXISTS (\n    SELECT 1\n    FROM events el\n    WHERE el.event_type IN ('EMAIL_LINKED', 'EMAIL_UNLINKED')\n      AND el.payload->>'email_id' = e.email_id::text\n)\nORDER BY e.received_at DESC\nLIMIT 1;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        208,
        -176
      ],
      "id": "78ade8f6-4677-4cc9-a544-4f78fa8208d5",
      "name": "Execute: Select emails that need linking",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "35c1f175-7507-4fcc-8ba5-0f5940b3b4d9",
              "leftValue": "={{ Number($json.company_count) === 1 }}",
              "rightValue": 1,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        912,
        0
      ],
      "id": "423b83f6-2510-40c6-b776-ab391d9dcfe4",
      "name": "Company match count"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT application_id\nFROM job_applications\nWHERE company_id = {{ $('Find company id').item.json.company_id }}\n  AND current_state NOT IN ('REJECTED','WITHDRAWN','ARCHIVED');\n",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1248,
        -192
      ],
      "id": "64275285-5b04-40b2-88d4-c342cc488571",
      "name": "Fetch active applications",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "b1c57086-0470-4abd-8a22-495230693eca",
              "leftValue": "={{ $items().length }}",
              "rightValue": 1,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        1456,
        -192
      ],
      "id": "63a9cabb-407c-4be6-94cd-768d84fefe47",
      "name": "Check Application count"
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "events",
          "mode": "list",
          "cachedResultName": "events"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "application_id": "={{ $json.application_id }}",
            "event_type": "EMAIL_LINKED",
            "triggered_by": "system",
            "payload": "={{{\n    email_id: $node[\"Extract sender domain\"].json.email_id,\n    link_reason: \"unique_company_and_application\"\n}\n}}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "application_id",
              "displayName": "application_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true
            },
            {
              "id": "payload",
              "displayName": "payload",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "object",
              "canBeUsedToMatch": true
            },
            {
              "id": "triggered_by",
              "displayName": "triggered_by",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1696,
        -272
      ],
      "id": "f6d91d00-9734-46f6-ac93-46fb33b90c98",
      "name": "Emit EMAIL_LINKED in events table",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "events",
          "mode": "list",
          "cachedResultName": "events"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_type": "EMAIL_UNLINKED",
            "payload": "={{\n  {\n    email_id: $node[\"Extract sender domain\"].json.email_id,\n    reason: \"no_unique_application\"\n  }\n}}",
            "triggered_by": "system",
            "application_id": 0
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "application_id",
              "displayName": "application_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true
            },
            {
              "id": "payload",
              "displayName": "payload",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "object",
              "canBeUsedToMatch": true
            },
            {
              "id": "triggered_by",
              "displayName": "triggered_by",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1680,
        -80
      ],
      "id": "3f0454c1-4aee-4492-a4e8-5163e1ce869a",
      "name": "emit EMAIL_UNLINKED ",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "events",
          "mode": "list",
          "cachedResultName": "events"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "payload": "={{\n  {\n    email_id: $node[\"Extract sender domain\"].json.email_id,\n    reason: \"no_unique_company\"\n  }\n}}",
            "event_type": "EMAIL_UNLINKED",
            "triggered_by": "system",
            "application_id": "={{ null }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "application_id",
              "displayName": "application_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true
            },
            {
              "id": "payload",
              "displayName": "payload",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "object",
              "canBeUsedToMatch": true
            },
            {
              "id": "triggered_by",
              "displayName": "triggered_by",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1056,
        224
      ],
      "id": "62691792-ff21-4080-acfb-96593cf0320e",
      "name": "Emit EMAIL_UNLINKED : company no match",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const sender = $json.sender;\nconst domain = sender.split('@')[1]?.toLowerCase() || null;\n\nreturn [{\n  json: {\n    email_id: $json.email_id,\n    sender_domain: domain\n  }\n}];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        384,
        144
      ],
      "id": "dc9fb0fa-a91b-49d8-9639-332305fb0d53",
      "name": "Extract sender domain"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT company_id\nFROM companies\nWHERE domain = '{{ $json.sender_domain }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        560,
        -96
      ],
      "id": "2053175f-fc2b-47d8-bae7-fd4c6f0b937c",
      "name": "Find company id",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT COUNT(*) AS company_count\nFROM companies\nWHERE domain = '{{ $('Extract sender domain').item.json.sender_domain }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        752,
        160
      ],
      "id": "8e3a8290-c3b4-47b9-9f2c-63cea2da2f78",
      "name": "Find Company Count",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 2,
              "triggerAtMinute": 5
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ],
      "id": "46c8d36c-4e23-41af-aaf8-aabc4a236c49",
      "name": "Schedule Trigger"
    }
  ],
  "connections": {
    "Execute: Select emails that need linking": {
      "main": [
        [
          {
            "node": "Extract sender domain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Company match count": {
      "main": [
        [
          {
            "node": "Fetch active applications",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Emit EMAIL_UNLINKED : company no match",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch active applications": {
      "main": [
        [
          {
            "node": "Check Application count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Application count": {
      "main": [
        [
          {
            "node": "Emit EMAIL_LINKED in events table",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "emit EMAIL_UNLINKED ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract sender domain": {
      "main": [
        [
          {
            "node": "Find company id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find company id": {
      "main": [
        [
          {
            "node": "Find Company Count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Company Count": {
      "main": [
        [
          {
            "node": "Company match count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Execute: Select emails that need linking",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "9a9839e7-01ed-44a0-a935-9e2f4e4aa2af",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "NPXJEahytPkoZhtB",
  "tags": []
}

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

job.3_email_application_linker. Uses postgres. Scheduled trigger; 11 nodes.

Source: https://github.com/daemon-Ad/Job-Aggregation-and-Email-Intelligence-System/blob/main/workflows/job.3_email_application_linker.json — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

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

Data & Sheets

Disparador 1.8. Uses itemLists, postgres, emailSend, httpRequest. Scheduled trigger; 85 nodes.

Item Lists, Postgres, Email Send +1
Data & Sheets

공유회_알림톡_크론. Uses postgres, httpRequest, n8n-nodes-solapi. Scheduled trigger; 39 nodes.

Postgres, HTTP Request, N8N Nodes Solapi
Data & Sheets

QuepasaAutomatic. Uses postgres, postgresTrigger, httpRequest. Scheduled trigger; 39 nodes.

Postgres, Postgres Trigger, HTTP Request
Data & Sheets

QuepasaAutomatic. Uses postgres, postgresTrigger, httpRequest. Scheduled trigger; 39 nodes.

Postgres, Postgres Trigger, HTTP Request
Data & Sheets

QuepasaAutomatic. Uses postgres, postgresTrigger, httpRequest. Scheduled trigger; 39 nodes.

Postgres, Postgres Trigger, HTTP Request