Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save danielkellyio/d8ea50c1d3b8d113ad2eb0a5d2000746 to your computer and use it in GitHub Desktop.

Select an option

Save danielkellyio/d8ea50c1d3b8d113ad2eb0a5d2000746 to your computer and use it in GitHub Desktop.
n8n Newsletter Workflow
{
"name": "Email Newsletter Subscribe",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "21e0b8b8-a1cb-48e2-b438-8fef16f7a604",
"responseMode": "responseNode",
"options": {}
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2.1,
"position": [
0,
0
],
"id": "52f4d0ec-281f-4b66-aeb7-796574fcab93",
"name": "Webhook",
"webhookId": "21e0b8b8-a1cb-48e2-b438-8fef16f7a604"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 3
},
"conditions": [
{
"id": "1ced78f7-9b3c-4568-86b2-609eda406579",
"leftValue": "={{ $json.isValid }}",
"rightValue": true,
"operator": {
"type": "boolean",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.3,
"position": [
384,
0
],
"id": "b8c88738-ede8-46ae-9d42-9614258d9035",
"name": "If"
},
{
"parameters": {
"operation": "upsert",
"dataTableId": {
"__rl": true,
"value": "20koqcqqcwHn5Jrp",
"mode": "list",
"cachedResultName": "subscribes",
"cachedResultUrl": "/projects/uDPdg0QOX75vyp49/datatables/20koqcqqcwHn5Jrp"
},
"filters": {
"conditions": [
{
"keyName": "email",
"keyValue": "={{ $json.email }}"
}
]
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"email": "={{ $json.email }}"
},
"matchingColumns": [
"email"
],
"schema": [
{
"id": "email",
"displayName": "email",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"readOnly": false,
"removed": false
}
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {}
},
"type": "n8n-nodes-base.dataTable",
"typeVersion": 1.1,
"position": [
624,
-96
],
"id": "0bb6a0cc-ec3a-4df8-9c03-00d35c21a2c3",
"name": "Insert Subscribe to DB"
},
{
"parameters": {
"sendTo": "={{ $json.email }}",
"subject": "Welcome to the Newlsetter!",
"message": "<h1>My welcome email here</h1>",
"options": {}
},
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.2,
"position": [
1040,
-96
],
"id": "8bbf8118-7188-4985-86ac-1effbf812119",
"name": "Send a message",
"webhookId": "030bc4eb-98a8-4f65-b4be-84bf95421c5c",
"credentials": {
"gmailOAuth2": {
"id": "xciTKc93KmIAHb3h",
"name": "Gmail account"
}
}
},
{
"parameters": {
"content": "## Newsletter SignUp\n",
"height": 80,
"width": 288
},
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
0,
-112
],
"id": "142e28a1-9b8a-4bde-8896-e9f092037ade",
"name": "Sticky Note"
},
{
"parameters": {
"content": "## Subscribe Valid Emails\nAnd send welcome email",
"height": 256,
"width": 656
},
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
560,
-192
],
"id": "f3e10d3d-ff74-4b82-adef-477c521290ff",
"name": "Sticky Note1"
},
{
"parameters": {
"jsCode": "const items = $input.all();\nconst emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nconst validatedEmails = items.map((item) => {\n const email = item?.json?.body?.email;\n const isValid = emailRegex.test(email);\n return { json: { email, isValid } };\n})\n\nreturn validatedEmails;\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
208,
0
],
"id": "02f19f65-3eeb-4c4f-b097-34064a164242",
"name": "Validate Email"
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ $('Insert Subscribe to DB').item.json }}",
"options": {}
},
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.5,
"position": [
832,
-96
],
"id": "47b6d287-7d1a-47c1-a683-e6195e4890ed",
"name": "Respond to Webhook"
},
{
"parameters": {
"respondWith": "json",
"responseBody": "{\n \"msg\": \"Invalid email address\"\n}",
"options": {
"responseCode": 422
}
},
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.5,
"position": [
624,
128
],
"id": "c8812bd0-b44b-4a25-a951-29a641deceb7",
"name": "Respond to Webhook1"
},
{
"parameters": {
"content": "\n\n\n\n\n\n\n\n\n\n\n\n\n## Handle Invalid Email",
"height": 224,
"width": 544
},
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
560,
80
],
"id": "e1968c84-a255-4135-b3b3-047fa0f0bd0c",
"name": "Sticky Note2"
}
],
"pinData": {
"Insert Subscribe to DB": [
{
"json": {
"email": "daniel@vueschool.io",
"id": 1,
"createdAt": "2026-01-05T14:55:06.704Z",
"updatedAt": "2026-01-05T14:59:48.631Z"
},
"pairedItem": {
"item": 0
}
}
]
},
"connections": {
"Webhook": {
"main": [
[
{
"node": "Validate Email",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "Insert Subscribe to DB",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond to Webhook1",
"type": "main",
"index": 0
}
]
]
},
"Insert Subscribe to DB": {
"main": [
[
{
"node": "Respond to Webhook",
"type": "main",
"index": 0
}
]
]
},
"Validate Email": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Respond to Webhook": {
"main": [
[
{
"node": "Send a message",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1",
"availableInMCP": false
},
"versionId": "cc704cd1-5fd0-4017-8b68-3b22d6d0a4e2",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "ebb22001e8f944cb3a2f1aba998d512e3eb57d72e310b2335d1e5f99c1aa636c"
},
"id": "BDEHmKwe02UoPURH",
"tags": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment