Email agent not working properly

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

{
“nodes”: [
{
“parameters”: {
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.chatTrigger”,
“typeVersion”: 1.1,
“position”: [
0,
0
],
“id”: “460206ad-a2e1-4012-bffd-bbca14b96d8b”,
“name”: “When chat message received”,
“webhookId”: “f24ffd61-5061-42ef-9f89-2a78eb74b0db”
},
{
“parameters”: {
“options”: {
“systemMessage”: “You are an AI Email Assistant”
}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 1.9,
“position”: [
220,
0
],
“id”: “c382700f-4e87-4792-b4d9-6a6ef5dd6d25”,
“name”: “AI Agent”
},
{
“parameters”: {
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatGroq”,
“typeVersion”: 1,
“position”: [
240,
220
],
“id”: “780d9f49-7c5c-443a-9ad9-93c00f52875b”,
“name”: “Groq Chat Model”,
“credentials”: {
“groqApi”: {
“id”: “7rdN6Ef1DW7vKAbA”,
“name”: “Groq account”
}
}
},
{
“parameters”: {
“select”: “channel”,
“channelId”: {
“__rl”: true,
“value”: “C08QF9L27HU”,
“mode”: “list”,
“cachedResultName”: “all-n8n-test”
},
“text”: “={{ $json.output }}”,
“otherOptions”: {
“includeLinkToWorkflow”: false
}
},
“type”: “n8n-nodes-base.slack”,
“typeVersion”: 2.3,
“position”: [
580,
0
],
“id”: “a97f9bda-f171-4e9f-ba00-09e69f55baf6”,
“name”: “Slack”,
“webhookId”: “6a190ed2-dba8-45d1-95d3-d9fd64bc9983”,
“credentials”: {
“slackApi”: {
“id”: “NBwGLJxzsSwKQjGf”,
“name”: “Slack account”
}
}
},
{
“parameters”: {},
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
-40,
560
],
“id”: “f0da005a-3dff-4dda-9579-c074a50e7280”,
“name”: “When clicking ‘Test workflow’”
},
{
“parameters”: {
“promptType”: “define”,
“text”: “{{$json.query}}”,
“options”: {
“systemMessage”: “You are an AI Email Assistant. Your job is to send emails on behalf of the user and log each send action. Follow these steps for every email task:\n\n1. Read the recipient’s email address from a specified Google Sheets document:\n - Connect to the provided Google Sheets.\n - Locate the correct row and column that contains the recipient’s email.\n\n2. Compose the email based on the user’s instructions:\n - Use the subject line and body template provided in the task.\n - Personalize the greeting using the recipient’s name when available.\n\n3. Send the email using the configured SMTP or email-sending service.\n\n4. After successfully sending the email:\n - Write back to the same Google Sheets row in a “Sent Timestamp” column.\n - Record the exact date and time (in UTC) when the email was sent.\n - Optionally, update a “Status” column to “Sent” or “Failed” if an error occurs.\n\n5. Error handling:\n - If the Sheets lookup fails, log an error message and do not attempt to send.\n - If sending fails, retry up to two times; if it still fails, record “Failed” in the status column and include the error message.\n\nAlways confirm each step’s success before proceeding to the next. Ensure data consistency in Google Sheets and reliable email delivery.```\n”
}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 1.9,
“position”: [
180,
560
],
“id”: “148ba626-b1ea-41c4-b721-98f8125b9244”,
“name”: “AI Agent1”
},
{
“parameters”: {
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatGroq”,
“typeVersion”: 1,
“position”: [
40,
800
],
“id”: “365215e3-2080-4d92-87b0-9db8546de132”,
“name”: “Groq Chat Model1”,
“credentials”: {
“groqApi”: {
“id”: “7rdN6Ef1DW7vKAbA”,
“name”: “Groq account”
}
}
},
{
“parameters”: {
“sessionIdType”: “customKey”,
“sessionKey”: “{{$now}}”
},
“type”: “@n8n/n8n-nodes-langchain.memoryBufferWindow”,
“typeVersion”: 1.3,
“position”: [
200,
800
],
“id”: “10b1a13a-1e45-4f82-ab42-454a4e32fd3f”,
“name”: “Simple Memory”
},
{
“parameters”: {
“documentId”: {
“__rl”: true,
“value”: “1CuPku4iB6xqgQP6K535C5o_3PTsKjrN0Mxa2EOllo_0”,
“mode”: “list”,
“cachedResultName”: “Contacts Whitelist”,
“cachedResultUrl”: “https://docs.google.com/spreadsheets/d/1CuPku4iB6xqgQP6K535C5o_3PTsKjrN0Mxa2EOllo_0/edit?usp=drivesdk
},
“sheetName”: {
“__rl”: true,
“value”: “gid=0”,
“mode”: “list”,
“cachedResultName”: “Sheet1”,
“cachedResultUrl”: “https://docs.google.com/spreadsheets/d/1CuPku4iB6xqgQP6K535C5o_3PTsKjrN0Mxa2EOllo_0/edit#gid=0
},
“options”: {}
},
“type”: “n8n-nodes-base.googleSheetsTool”,
“typeVersion”: 4.5,
“position”: [
340,
820
],
“id”: “0ff41709-6091-4367-841a-6c3844638339”,
“name”: “Google Sheets”,
“credentials”: {
“googleSheetsOAuth2Api”: {
“id”: “0daW15oqX89wI26k”,
“name”: “Google Sheets account”
}
}
},
{
“parameters”: {
“sendTo”: “={{ $fromAI(‘To’, , 'string') }}", "subject": "={{ $fromAI('Subject', , ‘string’) }}”,
“message”: “={{ $fromAI(‘Message’, ``, ‘string’) }}”,
“options”: {
“appendAttribution”: false
}
},
“type”: “n8n-nodes-base.gmailTool”,
“typeVersion”: 2.1,
“position”: [
480,
780
],
“id”: “40728983-afae-4db8-a38e-bbc50e5ae168”,
“name”: “Gmail”,
“webhookId”: “6f071673-e471-4599-93e4-0559e280a44c”,
“credentials”: {
“gmailOAuth2”: {
“id”: “kRSKH2drghfOBFUR”,
“name”: “Gmail account”
}
}
},
{
“parameters”: {
“name”: “Send_email”,
“description”: “call this tool to send email to user”,
“workflowId”: {
“__rl”: true,
“value”: “tdQ3sCnrnFp8EjHJ”,
“mode”: “id”
},
“workflowInputs”: {
“mappingMode”: “defineBelow”,
“value”: {},
“matchingColumns”: ,
“schema”: ,
“attemptToConvertTypes”: false,
“convertFieldsToString”: false
}
},
“type”: “@n8n/n8n-nodes-langchain.toolWorkflow”,
“typeVersion”: 2.1,
“position”: [
440,
200
],
“id”: “15f389f3-c1e1-4070-8446-989473801a4d”,
“name”: “Call n8n Workflow Tool”
}
],
“connections”: {
“When chat message received”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“AI Agent”: {
“main”: [
[
{
“node”: “Slack”,
“type”: “main”,
“index”: 0
}
]
]
},
“Groq Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“When clicking ‘Test workflow’”: {
“main”: [
[
{
“node”: “AI Agent1”,
“type”: “main”,
“index”: 0
}
]
]
},
“AI Agent1”: {
“main”: [

]
},
“Groq Chat Model1”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent1”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Simple Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent1”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“Google Sheets”: {
“ai_tool”: [
[
{
“node”: “AI Agent1”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Gmail”: {
“ai_tool”: [
[
{
“node”: “AI Agent1”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Call n8n Workflow Tool”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“instanceId”: “76e5f96cfa9819f7d28ecb93dc751a008ede0f116336a2f89cf98a1dc1540c53”
}
}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

Hi @Madan_Khadka
Can you put the code in a code block so it will render a workflow?

Yes, please do like this, if still having issues, we can help further if needed.

n8n attach workflow