AutomationFlowsAI & RAG › Email Task

Email Task

email-task. Uses openAi, gmail. Webhook trigger; 5 nodes.

Webhook trigger★★★★☆ complexityAI-powered5 nodesOpenAIGmail
AI & RAG Trigger: Webhook Nodes: 5 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Gmail → OpenAI 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
{
  "name": "email-task",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "email-task",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1140,
        260
      ],
      "id": "0e609747-c5e8-40b1-821e-197d92a7b9ac",
      "name": "Email Webhook"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "provider-2/gpt-3.5-turbo",
          "mode": "id"
        },
        "messages": {
          "values": [
            {
              "content": "You are a professional email writing assistant. Create well-structured, professional emails based on user requests. Always return ONLY a valid JSON object with 'subject' and 'body' fields. Example: {\"subject\": \"Meeting Request\", \"body\": \"Dear Recipient,\\n\\nContent here...\\n\\nBest regards,\\nSender\"}",
              "role": "system"
            },
            {
              "content": "=Create a professional email with the following details:\n- To: {{ $json.body.recipientEmail }}\n- Content:{{ $json.body.content }}\n- Tone: {{ $json.body.tone || 'professional' }}\n- From: {{ $json.body.senderName || 'User' }}\n\nReturn only a JSON object with 'subject' and 'body' fields."
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        -660,
        260
      ],
      "id": "37f96268-6b29-4454-b390-3822ca6c3a16",
      "name": "Generate Email",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Process the AI response and format for Android app\nconst webhookData = $('Email Webhook').first().json;\nconst aiResponse = $input.first().json;\n\nlet emailData;\ntry {\n  // Get AI response content\n  const content = aiResponse.message?.content || aiResponse.text || aiResponse.content || '';\n  \n  // Try to parse as JSON\n  try {\n    emailData = JSON.parse(content.trim());\n  } catch {\n    // Fallback parsing if not JSON\n    const lines = content.split('\\n').filter(line => line.trim());\n    const subject = lines[0]?.replace(/.*subject[:\\s]*/i, '') || 'Email';\n    const body = lines.slice(1).join('\\n') || webhookData.body?.content || webhookData.content || 'Email content';\n    emailData = { subject, body };\n  }\n  \n  const executionId = 'email_' + Date.now();\n  \n  // Return response in the exact format expected by Android app\n  return {\n    id: executionId,\n    status: 'success',\n    data: {\n      id: executionId,\n      status: 'sent',\n      recipient: webhookData.body?.recipientEmail || webhookData.recipientEmail,\n      subject: emailData.subject?.replace(/[\"']/g, '') || 'Email',\n      body: emailData.body?.replace(/\\\\n/g, '\\n') || webhookData.body?.content || webhookData.content,\n      timestamp: new Date().toISOString(),\n      senderName: webhookData.body?.senderName || webhookData.senderName || 'User',\n      tone: webhookData.body?.tone || webhookData.tone || 'professional',\n      message: 'Email sent successfully',\n      messageId: 'gmail_' + Date.now()\n    }\n  };\n  \n} catch (error) {\n  // Return error response in expected format\n  const executionId = 'email_error_' + Date.now();\n  \n  return {\n    id: executionId,\n    status: 'error',\n    error: 'Failed to generate email: ' + error.message,\n    data: {\n      recipient: webhookData.body?.recipientEmail || webhookData.recipientEmail,\n      originalContent: webhookData.body?.content || webhookData.content,\n      timestamp: new Date().toISOString()\n    }\n  };\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -200,
        400
      ],
      "id": "3dbb53d4-7697-4d44-a6eb-737ae7a74606",
      "name": "Process Response"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        20,
        200
      ],
      "id": "bdcda968-e8d9-4468-9f1c-3e5a8c5ef4a9",
      "name": "Send Response"
    },
    {
      "parameters": {
        "sendTo": "={{ $('Email Webhook').item.json.body.recipientEmail }}",
        "subject": "={{ $json.message.content.parseJson().subject }}",
        "message": "={{ $json.message.content.parseJson().body }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "0e2afa45-46d6-4ad6-8a2a-c563806f431a",
      "name": "Send a message",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Email Webhook": {
      "main": [
        [
          {
            "node": "Generate Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Email": {
      "main": [
        [
          {
            "node": "Process Response",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Response": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5fa223b2-68d1-49c3-8b96-3a113d310cb0",
  "id": "QRlnf6DeoK9zGD4l",
  "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

email-task. Uses openAi, gmail. Webhook trigger; 5 nodes.

Source: https://github.com/masteranany23/TaskIt/blob/a25cceccbf0ce9b0b9d1320351c46493a60f25b9/n8n-workflows/email_task.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

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

AI & RAG

Eu Clara – Funil Kiwify Completo. Uses postgres, openAi, httpRequest, gmail. Webhook trigger; 70 nodes.

Postgres, OpenAI, HTTP Request +1
AI & RAG

User Signup & Verification: The workflow starts when a user signs up. It generates a verification code and sends it via SMS using Twilio. Code Validation: The user replies with the code. The workflow

Postgres, HTTP Request, OpenAI +2
AI & RAG

Instantly map all internal URLs, perform AI-powered (ChatGPT) analysis, and deliver results in HTML via webhook, Google Sheets, or email. All from your own n8n instance!

OpenAI, HTTP Request, XML +3
AI & RAG

Watch on Youtube▶️

HTTP Request, Email Send, Google Sheets +3
AI & RAG

This is for creators who run Patreon and/or Kofi pages, support donations and want to automate their communication process.

Gmail, Google Sheets, OpenAI