{
  "name": "Email to Slack",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "mailbox": "INBOX",
        "options": {
          "customEmailConfig": "UNSEEN"
        }
      },
      "id": "email-trigger",
      "name": "Email Trigger",
      "type": "n8n-nodes-base.emailTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ],
      "credentials": {
        "imap": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.from }}",
                    "rightValue": "urgent|important|alert",
                    "operator": {
                      "type": "string",
                      "operation": "regex"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "urgent"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.subject }}",
                    "rightValue": "invoice|payment|order",
                    "operator": {
                      "type": "string",
                      "operation": "regex"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "business"
            }
          ]
        }
      },
      "id": "switch-node",
      "name": "Filter Rules",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 2,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Format email for Slack\nconst email = $input.first().json;\nconst branch = $branchName; // 'urgent' or 'business'\n\n// Emoji based on type\nconst emoji = branch === 'urgent' ? '\ud83d\udea8' : '\ud83d\udcbc';\n\n// Channel based on type\nconst channel = branch === 'urgent' ? '#alerts' : '#notifications';\n\n// Truncate preview\nconst preview = email.text?.substring(0, 200) || 'No preview available';\n\nreturn {\n  channel: channel,\n  text: `${emoji} *New Important Email*,\n  blocks: [\n    {\n      type: 'header',\n      text: {\n        type: 'plain_text',\n        text: `${emoji} New Important Email`\n      }\n    },\n    {\n      type: 'section',\n      fields: [\n        {\n          type: 'mrkdwn',\n          text: `*From:*\\n${email.from}`\n        },\n        {\n          type: 'mrkdwn',\n          text: `*Subject:*\\n${email.subject}`\n        }\n      ]\n    },\n    {\n      type: 'section',\n      text: {\n        type: 'mrkdwn',\n        text: `*Preview:*\\n${preview}${email.text?.length > 200 ? '...' : ''}`\n      }\n    },\n    {\n      type: 'context',\n      elements: [\n        {\n          type: 'mrkdwn',\n          text: `\ud83d\udcc5 ${new Date(email.date).toLocaleString()}`\n        }\n      ]\n    },\n    {\n      type: 'actions',\n      elements: [\n        {\n          type: 'button',\n          text: {\n            type: 'plain_text',\n            text: 'Reply'\n          },\n          url: `mailto:${email.from}?subject=Re: ${email.subject}`\n        }\n      ]\n    }\n  ],\n  originalEmail: email\n};"
      },
      "id": "format-node",
      "name": "Format Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "channel": "={{ $json.channel }}",
        "text": "={{ $json.text }}",
        "blocks": "={{ $json.blocks }}",
        "otherOptions": {}
      },
      "id": "slack-node",
      "name": "Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Email Trigger": {
      "main": [
        [
          {
            "node": "Filter Rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Rules": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Message": {
      "main": [
        [
          {
            "node": "Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2026-03-02T19:00:00.000Z",
  "versionId": "1"
}