{
  "id": "uBq9fV9dOKnxTCjp",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Lead Auto-Email Template",
  "tags": [],
  "nodes": [
    {
      "id": "c0fc92e8-c858-4ac4-bb4d-65575f37ffa2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4272,
        416
      ],
      "parameters": {
        "width": 480,
        "height": 896,
        "content": "## Notion CRM Lead Outreach with Bounce Handling\n\n### How it works\n\n1. The workflow triggers upon a new CRM lead from Notion or a Gmail bounce.\n2. It validates email addresses and checks if emails have been previously sent.\n3. Depending on conditions, it sends personalized or generic outreach emails with attachments.\n4. Emails are monitored for bounces, triggering mark invalid processes in the CRM.\n5. Workflow concludes by updating lead information in the CRM database.\n\n### Setup steps\n\n- [ ] Configure Notion and Gmail API credentials for node integration.\n- [ ] Set up OpenAI credentials for text processing.\n- [ ] Ensure Twilio account is connected for notifications.\n\n### Customization\n\nThe email templates and criteria for personalized or generic outreach can be customized. Additionally, conditions for marking emails invalid can be adjusted."
      },
      "typeVersion": 1
    },
    {
      "id": "914d334c-bf25-4597-b96e-a6df31fc65e8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4912,
        448
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 320,
        "content": "## Trigger new CRM lead\n\nInitiates workflow upon new lead detection in Notion."
      },
      "typeVersion": 1
    },
    {
      "id": "281238ed-1ff6-4a50-9f81-2ab3ff8ff0ff",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5216,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 704,
        "height": 496,
        "content": "## Validate email and search sent\n\nValidates email addresses and searches sent emails to check if an email has already been sent."
      },
      "typeVersion": 1
    },
    {
      "id": "54ada9cc-a991-4eb8-ba55-56eb49c12957",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5920,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 496,
        "content": "## Flag email status\n\nSets flags for previously emailed leads and checks flags for conditional branching."
      },
      "typeVersion": 1
    },
    {
      "id": "85fdae60-6ead-4cd8-952e-6085bb289bce",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6352,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 320,
        "content": "## Handle previously emailed leads\n\nHandles cases where leads have already been emailed, marking them accordingly."
      },
      "typeVersion": 1
    },
    {
      "id": "0baec5c0-6446-4278-911c-3d3dd39db040",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6528,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 1344,
        "height": 512,
        "content": "## Prepare and send emails\n\nDownloads attachments, prepares and sends outreach emails (both generic and personalized)."
      },
      "typeVersion": 1
    },
    {
      "id": "ed5c4a6b-c781-449b-8b57-e8a0ceec1d0c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7872,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 1056,
        "height": 512,
        "content": "## Email bounce detection and handling\n\nMonitors for email bounces, and processes bounced emails in Notion."
      },
      "typeVersion": 1
    },
    {
      "id": "7d08c693-8685-4050-b330-82aff8162cf2",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4896,
        992
      ],
      "parameters": {
        "color": 7,
        "width": 1376,
        "height": 336,
        "content": "## Gmail bounce trigger\n\nChecks for initial bounce notifications from Gmail triggers."
      },
      "typeVersion": 1
    },
    {
      "id": "3ecf02dc-a419-4c03-8041-8070612eca5c",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7568,
        48
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 304,
        "content": "## Draft notification process\n\nNotifies reps about email drafts created for review."
      },
      "typeVersion": 1
    },
    {
      "id": "851ec26a-5776-4e26-b204-497c5094b675",
      "name": "When CRM Lead Added to Notion",
      "type": "n8n-nodes-base.notionTrigger",
      "notes": "Triggers when a CRM lead page is updated. Use a filtered database/status so only ready-to-email leads are processed.",
      "position": [
        4992,
        592
      ],
      "parameters": {
        "event": "pagedUpdatedInDatabase",
        "pollTimes": {
          "item": [
            {
              "mode": "everyX",
              "unit": "minutes",
              "value": 10
            }
          ]
        },
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": "Select your CRM / Notion database"
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "734eeeaf-6960-41dd-b554-362ec7b61b85",
      "name": "Check Valid Email Format",
      "type": "n8n-nodes-base.if",
      "notes": "Continues only when the lead has something that looks like an email address.",
      "position": [
        5264,
        592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3803f923-2b2c-4e13-9eb3-55e3b9066094",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.Email }}",
              "rightValue": "@"
            },
            {
              "id": "1b765834-1852-469f-afd1-a04929679896",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.Email }}",
              "rightValue": "."
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "f45ba2bd-f43c-4145-ad03-071486a3e05f",
      "name": "If Previously Emailed",
      "type": "n8n-nodes-base.if",
      "notes": "True path handles leads that were already emailed. False path continues to outreach.",
      "position": [
        6192,
        512
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "c4e09f38-2323-4f46-9b5a-c5dcf8c7e3e0",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.previouslyEmailed }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3,
      "alwaysOutputData": false
    },
    {
      "id": "172166b2-7117-4935-a21f-99f16f7da79e",
      "name": "Send Personalized Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "notes": "Sends the outreach email with attachments. Replace the template copy before using with real leads.",
      "onError": "continueErrorOutput",
      "position": [
        7648,
        704
      ],
      "parameters": {
        "sendTo": "={{ $('When CRM Lead Added to Notion').item.json.Email }}",
        "message": "=<p>Hi {{ $('When CRM Lead Added to Notion').item.json['Contact Name'] }},</p>\n\n<p>Thank you for taking the time to speak with me.</p>\n\n<p>As discussed, <strong>[YOUR_COMPANY_NAME]</strong> can help with <strong>[YOUR_PRODUCT_OR_SERVICE]</strong>.</p>\n\n<p><strong>Included:</strong></p>\n<ul>\n  <li>[Benefit or deliverable #1]</li>\n  <li>[Benefit or deliverable #2]</li>\n  <li>[Benefit or deliverable #3]</li>\n</ul>\n\n<p>I attached the relevant information for your review.</p>\n\n<p>Would you be open to a quick 15-minute call or demo to walk through how it works?</p>\n\n<p>Please let me know a date and time that works best for you.</p>\n\n<br>\n\n<p>\nBest regards,<br>\n[YOUR_NAME]<br>\n[YOUR_TITLE]\n</p>\n\n<p>\n<strong>[YOUR_COMPANY_NAME]</strong><br>\n[YOUR_PHONE_NUMBER] | <a href=\"https://yourcompany.com\">yourcompany.com</a><br>\n[YOUR_COMPANY_ADDRESS]\n</p>",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "pdf1"
              },
              {
                "property": "pdf2"
              }
            ]
          },
          "appendAttribution": false
        },
        "subject": "[YOUR_COMPANY_NAME] \u2013 [YOUR_PRODUCT_OR_SERVICE]"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "059e8461-b6b8-4ed0-adb6-1152556d2db2",
      "name": "Update Notion for Emailed Lead",
      "type": "n8n-nodes-base.notion",
      "notes": "Updates the CRM lead status after an email was found/sent. Customize the Status value to match your database.",
      "position": [
        8736,
        704
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When CRM Lead Added to Notion').item.json.id }}"
        },
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Status|status",
              "statusValue": "Emailed"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c7bc4104-7cbe-4477-8b50-20d624a416b1",
      "name": "Fetch Sent Mail from Account",
      "type": "n8n-nodes-base.gmail",
      "notes": "Searches sent mail to prevent duplicate outreach to the same email address.",
      "position": [
        5536,
        672
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "q": "={{ 'to:' + $('When CRM Lead Added to Notion').item.json.Email + ' newer_than:365d' }}"
        },
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "95ed344c-debf-4424-803e-b95d3102fae9",
      "name": "Download Specs PDF from Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "notes": "Select the Google Drive file you want attached to the outreach email.",
      "position": [
        6640,
        480
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": "Select attachment PDF"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "8ae53e50-66c4-4874-85f9-6a2857bcd7cd",
      "name": "Download Proposal PDF from Drive",
      "type": "n8n-nodes-base.googleDrive",
      "notes": "Select the Google Drive file you want attached to the outreach email.",
      "position": [
        6640,
        688
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": "Select attachment PDF"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "2a395210-39f3-48aa-984a-95010e13f13e",
      "name": "Convert to Attachment Binaries",
      "type": "n8n-nodes-base.code",
      "notes": "Combines downloaded Drive files into binary properties that Gmail can attach.",
      "position": [
        7072,
        576
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// This template expects two downloaded files.\n// Rename binary properties if your Gmail node expects different attachment names.\nreturn [\n  {\n    json: {},\n    binary: {\n      pdf1: items[0]?.binary?.data,\n      pdf2: items[1]?.binary?.data,\n    },\n  },\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "c3189f29-b31f-4bf0-ae70-9305c4f9adca",
      "name": "Merge Attachment PDFs",
      "type": "n8n-nodes-base.merge",
      "position": [
        6880,
        576
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "f220b1d5-a0e5-4776-a42a-a44d21606b1e",
      "name": "Fetch Sent Mail from Account 3",
      "type": "n8n-nodes-base.gmail",
      "notes": "Searches sent mail to prevent duplicate outreach to the same email address.",
      "position": [
        5536,
        480
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "q": "={{ 'to:' + $('When CRM Lead Added to Notion').item.json.Email + ' newer_than:365d' }}"
        },
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "93788a06-3d49-4bc3-95e0-d7c8a8eda6d3",
      "name": "Determine Contact Name",
      "type": "n8n-nodes-base.if",
      "notes": "Chooses personalized greeting when Contact Name exists; generic greeting when it is empty.",
      "position": [
        7424,
        592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d66d1ef3-35d4-4fc8-bd7c-887020465291",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json['Contact Name'] }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a473e890-7dbe-4bb3-8ddb-7d39a802a5a7",
      "name": "Send Generic Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "notes": "Sends the outreach email with attachments. Replace the template copy before using with real leads.",
      "onError": "continueErrorOutput",
      "position": [
        7648,
        496
      ],
      "parameters": {
        "sendTo": "={{ $('When CRM Lead Added to Notion').item.json.Email }}",
        "message": "=<p>Hi there,</p>\n\n<p>Thank you for taking the time to speak with me.</p>\n\n<p>As discussed, <strong>[YOUR_COMPANY_NAME]</strong> can help with <strong>[YOUR_PRODUCT_OR_SERVICE]</strong>.</p>\n\n<p><strong>Included:</strong></p>\n<ul>\n  <li>[Benefit or deliverable #1]</li>\n  <li>[Benefit or deliverable #2]</li>\n  <li>[Benefit or deliverable #3]</li>\n</ul>\n\n<p>I attached the relevant information for your review.</p>\n\n<p>Would you be open to a quick 15-minute call or demo to walk through how it works?</p>\n\n<p>Please let me know a date and time that works best for you.</p>\n\n<br>\n\n<p>\nBest regards,<br>\n[YOUR_NAME]<br>\n[YOUR_TITLE]\n</p>\n\n<p>\n<strong>[YOUR_COMPANY_NAME]</strong><br>\n[YOUR_PHONE_NUMBER] | <a href=\"https://yourcompany.com\">yourcompany.com</a><br>\n[YOUR_COMPANY_ADDRESS]\n</p>",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "pdf1"
              },
              {
                "property": "pdf2"
              }
            ]
          },
          "appendAttribution": false
        },
        "subject": "[YOUR_COMPANY_NAME] \u2013 [YOUR_PRODUCT_OR_SERVICE]"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "075acc50-cbeb-4a61-8ffa-dfbd42328f36",
      "name": "Wait for Bounce Notification",
      "type": "n8n-nodes-base.wait",
      "position": [
        7936,
        608
      ],
      "parameters": {
        "amount": 15
      },
      "typeVersion": 1.1
    },
    {
      "id": "5b0dfcb9-a085-4788-825b-654d72a9821d",
      "name": "Fetch Bounce Emails in Gmail",
      "type": "n8n-nodes-base.gmail",
      "notes": "Searches Gmail shortly after sending to see whether a bounce email appeared.",
      "position": [
        8112,
        608
      ],
      "parameters": {
        "limit": 2,
        "filters": {
          "q": "={{ 'in:anywhere \"Address not found\" \"' + $('When CRM Lead Added to Notion').item.json.Email + '\"' }}"
        },
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "28021bc7-a9e9-490e-b79b-13d05c15f180",
      "name": "If Bounce Detected",
      "type": "n8n-nodes-base.if",
      "notes": "If a bounce exists, marks the CRM lead as INVALID EMAIL.",
      "position": [
        8288,
        592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "538b1861-b4c1-4607-94da-3ad13d924c03",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "ba886107-200c-48be-8778-9cb27bfdcb18",
      "name": "Update Notion for Invalid Email",
      "type": "n8n-nodes-base.notion",
      "position": [
        8512,
        480
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When CRM Lead Added to Notion').item.json.id }}"
        },
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Notes|rich_text",
              "textContent": "Email bounced / address not found"
            },
            {
              "key": "Status|status",
              "statusValue": "INVALID EMAIL"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e3c24a38-4714-4ed6-bddb-b431e731f372",
      "name": "Process Already Emailed Lead",
      "type": "n8n-nodes-base.if",
      "notes": "Only auto-marks safe lead statuses as emailed. Customize these CRM status values to match your pipeline.",
      "position": [
        6400,
        192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5e264b40-4e34-44f9-a690-2173453b2d7a",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Status }}",
              "rightValue": "Warm Lead"
            },
            {
              "id": "7770d08d-f716-4a54-babb-f831a218e838",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Status }}",
              "rightValue": "Interested"
            },
            {
              "id": "ccd6e507-8920-47f9-9196-8d88caa97eda",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Status }}",
              "rightValue": "Not Interested"
            },
            {
              "id": "8ed07f6b-2588-4c31-97d8-be02a7ea706b",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Status }}",
              "rightValue": "INVALID EMAIL"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "1773beb7-e2f6-4f26-8385-c2df70d94ac8",
      "name": "Update Notion for Already Emailed",
      "type": "n8n-nodes-base.notion",
      "notes": "Updates the CRM lead status after an email was found/sent. Customize the Status value to match your database.",
      "position": [
        6640,
        176
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When CRM Lead Added to Notion').item.json.id }}"
        },
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Status|status",
              "statusValue": "Emailed"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2c273f89-426c-4ed3-9168-b275371004b8",
      "name": "If Can Update Lead Status",
      "type": "n8n-nodes-base.if",
      "notes": "Prevents overwriting important statuses like Interested or Not Interested.",
      "position": [
        8512,
        688
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "dc6e59e3-1886-4a27-8710-d61c12a256ed",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Status }}",
              "rightValue": "Warm Lead"
            },
            {
              "id": "63ab4371-a0da-4785-ae01-98e7085be0ce",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Status }}",
              "rightValue": "Interested"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "edeb6bf1-710f-4753-96c0-91af8d415c0d",
      "name": "Merge Sent Emails Results",
      "type": "n8n-nodes-base.merge",
      "position": [
        5776,
        576
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "080d9616-4a4c-4b41-9f2c-268257860503",
      "name": "Flag as Previously Emailed",
      "type": "n8n-nodes-base.code",
      "notes": "Combines the Gmail search results into one boolean flag: previouslyEmailed.",
      "position": [
        5984,
        576
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// If either Gmail search found an existing message/thread, mark this lead as already contacted.\nconst found = items.some(item => item.json.id || item.json.threadId);\n\nreturn [\n  {\n    json: {\n      previouslyEmailed: found,\n      checkedAt: new Date().toISOString(),\n    },\n  },\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "1fcea5f4-6ad4-4515-a4a9-b9f6904b8f8a",
      "name": "Wait 7 Seconds",
      "type": "n8n-nodes-base.wait",
      "notes": "Optional short delay before sending/downloading attachments. Increase or remove based on your use case.",
      "position": [
        6432,
        592
      ],
      "parameters": {
        "amount": 7
      },
      "typeVersion": 1.1
    },
    {
      "id": "c8e7e4f5-6c75-4f6b-8de7-eb296141deb2",
      "name": "Check Draft Review Domain",
      "type": "n8n-nodes-base.if",
      "notes": "Optional safeguard: create a draft for certain domains/accounts instead of auto-sending.",
      "position": [
        7248,
        576
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1a5b3a0e-1620-4ccf-a782-04a161925480",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $('When CRM Lead Added to Notion').item.json.Email }}",
              "rightValue": "example.com"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "56b6dc85-800a-4c3f-b7a4-4a2fd8140380",
      "name": "Create Gmail Draft for Approval",
      "type": "n8n-nodes-base.gmail",
      "notes": "Creates a Gmail draft instead of sending automatically for leads/domains that need manual review.",
      "position": [
        7424,
        416
      ],
      "parameters": {
        "message": "=<p>Hi {{ $('When CRM Lead Added to Notion').item.json['Contact Name'] }},</p>\n\n<p>Thank you for taking the time to speak with me.</p>\n\n<p>As discussed, <strong>[YOUR_COMPANY_NAME]</strong> can help with <strong>[YOUR_PRODUCT_OR_SERVICE]</strong>.</p>\n\n<p><strong>Included:</strong></p>\n<ul>\n  <li>[Benefit or deliverable #1]</li>\n  <li>[Benefit or deliverable #2]</li>\n  <li>[Benefit or deliverable #3]</li>\n</ul>\n\n<p>I attached the relevant information for your review.</p>\n\n<p>Would you be open to a quick 15-minute call or demo to walk through how it works?</p>\n\n<p>Please let me know a date and time that works best for you.</p>\n\n<br>\n\n<p>\nBest regards,<br>\n[YOUR_NAME]<br>\n[YOUR_TITLE]\n</p>\n\n<p>\n<strong>[YOUR_COMPANY_NAME]</strong><br>\n[YOUR_PHONE_NUMBER] | <a href=\"https://yourcompany.com\">yourcompany.com</a><br>\n[YOUR_COMPANY_ADDRESS]\n</p>",
        "options": {
          "sendTo": "={{ $('When CRM Lead Added to Notion').item.json.Email }}",
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "pdf1"
              },
              {
                "property": "pdf2"
              }
            ]
          }
        },
        "subject": "[YOUR_COMPANY_NAME] \u2013 [YOUR_PRODUCT_OR_SERVICE]",
        "resource": "draft",
        "emailType": "html"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c07c9c59-d545-46e2-8a86-6b8c73644eef",
      "name": "Notify Rep via Twilio",
      "type": "n8n-nodes-base.twilio",
      "notes": "Optional SMS alert to the sales rep when a review draft is created. Replace or remove this node if not needed.",
      "position": [
        7616,
        192
      ],
      "parameters": {
        "to": "[YOUR_REP_PHONE_NUMBER]",
        "from": "[YOUR_TWILIO_NUMBER]",
        "message": "={{ 'Draft created for ' + $('When CRM Lead Added to Notion').item.json.Email + '. Please review it in Gmail before sending.' }}",
        "options": {}
      },
      "credentials": {
        "twilioApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e4073453-0efc-4434-b3ac-ca5744e5f519",
      "name": "When Gmail Bounce Detected",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        4944,
        1168
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "8f9b49c3-ca93-43a1-aa45-836d2a2c8b87",
      "name": "If Bounce Notification Exists",
      "type": "n8n-nodes-base.if",
      "notes": "Separate bounce handler: detects Gmail delivery failure messages as they arrive.",
      "position": [
        5152,
        1168
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1c869015-6a9c-42dd-8734-bc0d77975b6c",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.snippet }}",
              "rightValue": "Address not found"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "1942a3ff-42c9-466c-932d-0ebc6b07e61c",
      "name": "Extract Bounced Email Address",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Uses an LLM to extract only the failed email address from a bounce message. Replace model as needed.",
      "position": [
        5360,
        1104
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "={{ $json.snippet }}\n\nExtract the invalid/bounced email address.\n\nReturn only the email address. No quotes, no dashes, no explanation."
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "7c8c9c8a-3c40-4cd2-b3d6-9a7e78ceb436",
      "name": "Fetch All CRM Leads",
      "type": "n8n-nodes-base.notion",
      "notes": "Loads CRM leads so the bounced email can be matched back to the correct record.",
      "position": [
        5712,
        1104
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": "Select your CRM / Notion database"
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4bbf8caf-3348-4f1d-a1d8-2414ae48a521",
      "name": "Update Notion for Bounced Lead",
      "type": "n8n-nodes-base.notion",
      "position": [
        6128,
        1104
      ],
      "parameters": {
        "pageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Status|status",
              "statusValue": "INVALID EMAIL"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3abb645e-670d-4e7c-88d7-ab549f20c22c",
      "name": "Find Matching Bounced Lead",
      "type": "n8n-nodes-base.if",
      "notes": "Matches the extracted bounced email to the CRM Email field.",
      "position": [
        5920,
        1104
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "948f0403-7beb-4379-9e56-86579ae7040c",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Email }}",
              "rightValue": "={{ $('Extract Bounced Email Address').item.json.output[0].content[0].text }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "6b411960-c4d3-4dba-be41-09f3842d23f8",
  "nodeGroups": [],
  "connections": {
    "Wait 7 Seconds": {
      "main": [
        [
          {
            "node": "Download Proposal PDF from Drive",
            "type": "main",
            "index": 0
          },
          {
            "node": "Download Specs PDF from Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Bounce Detected": {
      "main": [
        [
          {
            "node": "Update Notion for Invalid Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If Can Update Lead Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch All CRM Leads": {
      "main": [
        [
          {
            "node": "Find Matching Bounced Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Previously Emailed": {
      "main": [
        [
          {
            "node": "Process Already Emailed Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 7 Seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Attachment PDFs": {
      "main": [
        [
          {
            "node": "Convert to Attachment Binaries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Determine Contact Name": {
      "main": [
        [
          {
            "node": "Send Generic Email via Gmail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Personalized Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Valid Email Format": {
      "main": [
        [
          {
            "node": "Fetch Sent Mail from Account 3",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Sent Mail from Account",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Draft Review Domain": {
      "main": [
        [
          {
            "node": "Create Gmail Draft for Approval",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Determine Contact Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Can Update Lead Status": {
      "main": [
        [],
        [
          {
            "node": "Update Notion for Emailed Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Sent Emails Results": {
      "main": [
        [
          {
            "node": "Flag as Previously Emailed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Matching Bounced Lead": {
      "main": [
        [
          {
            "node": "Update Notion for Bounced Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flag as Previously Emailed": {
      "main": [
        [
          {
            "node": "If Previously Emailed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Gmail Bounce Detected": {
      "main": [
        [
          {
            "node": "If Bounce Notification Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Bounce Emails in Gmail": {
      "main": [
        [
          {
            "node": "If Bounce Detected",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Sent Mail from Account": {
      "main": [
        [
          {
            "node": "Merge Sent Emails Results",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Process Already Emailed Lead": {
      "main": [
        [
          {
            "node": "Update Notion for Already Emailed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Generic Email via Gmail": {
      "main": [
        [
          {
            "node": "Wait for Bounce Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Bounce Notification": {
      "main": [
        [
          {
            "node": "Fetch Bounce Emails in Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Bounced Email Address": {
      "main": [
        [
          {
            "node": "Fetch All CRM Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Bounce Notification Exists": {
      "main": [
        [
          {
            "node": "Extract Bounced Email Address",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When CRM Lead Added to Notion": {
      "main": [
        [
          {
            "node": "Check Valid Email Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Attachment Binaries": {
      "main": [
        [
          {
            "node": "Check Draft Review Domain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Sent Mail from Account 3": {
      "main": [
        [
          {
            "node": "Merge Sent Emails Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Gmail Draft for Approval": {
      "main": [
        [
          {
            "node": "Notify Rep via Twilio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Proposal PDF from Drive": {
      "main": [
        [
          {
            "node": "Merge Attachment PDFs",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Send Personalized Email via Gmail": {
      "main": [
        [
          {
            "node": "Wait for Bounce Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Specs PDF from Google Drive": {
      "main": [
        [
          {
            "node": "Merge Attachment PDFs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}