AI 生成的电子邮件通讯
中级
这是一个AI, Marketing领域的自动化工作流,包含 8 个节点。主要使用 Set, Code, Gmail, Agent, ScheduleTrigger 等节点,结合人工智能技术实现智能自动化。 使用 GPT 和 Gmail 自动生成并发送 AI 新闻通讯
前置要求
- •Google 账号和 Gmail API 凭证
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "DSxmKG8H861zKUw8",
"meta": {
"instanceId": "18c9b77a7db94bab09d77f4a9c44dd94853695bba1618cb7bc3c4bc412c07c1e",
"templateCredsSetupCompleted": true
},
"name": "AI 生成的电子邮件通讯",
"tags": [],
"nodes": [
{
"id": "a915b64b-1052-4cd1-aca9-0325c1b2c29d",
"name": "工作流文档",
"type": "n8n-nodes-base.stickyNote",
"position": [
-120,
-140
],
"parameters": {
"color": 6,
"width": 450,
"height": 420,
"content": "## 每日 AI 新闻摘要工作流"
},
"typeVersion": 1
},
{
"id": "3c6ef52a-3c4b-4d0e-be08-d496c407fa66",
"name": "设置说明",
"type": "n8n-nodes-base.stickyNote",
"position": [
480,
0
],
"parameters": {
"color": 3,
"width": 580,
"height": 280,
"content": "⚙️ **需要配置:**"
},
"typeVersion": 1
},
{
"id": "2f165ff5-7666-4f7b-93e0-73556ad9ed7a",
"name": "设置日期1",
"type": "n8n-nodes-base.set",
"position": [
60,
360
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "current-date",
"name": "currentDate",
"type": "string",
"value": "={{ $now.format('yyyy-MM-dd') }}"
},
{
"id": "yesterday-date",
"name": "lastweekDate",
"type": "string",
"value": "={{ $now.minus({days: 7}).format('yyyy-MM-dd') }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "419a0eac-33f1-4349-ba54-a0a428ef8c1b",
"name": "Gmail1",
"type": "n8n-nodes-base.gmail",
"position": [
880,
360
],
"webhookId": "6e5776e8-b6b9-4c56-8b3a-812f68959433",
"parameters": {
"sendTo": "jyothi.swarup@techdome.net.in",
"message": "={{ $json.html }}",
"options": {},
"subject": "={{ $json.subject }}"
},
"credentials": {
"gmailOAuth2": {
"id": "kqndcZ7sNbQqDrJF",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "57cb8666-b3ff-489b-a6a5-be329ad82ab5",
"name": "格式化邮件内容",
"type": "n8n-nodes-base.code",
"position": [
660,
360
],
"parameters": {
"jsCode": "// n8n Code Node - Email Formatter for AI Newsletter\n// This code formats the AI agent output for email sending\n\n// Get the AI agent output from the previous node\nconst aiOutput = $input.all()[0].json.output || $input.all()[0].json.text || $input.all()[0].json;\n\n// Extract the newsletter content (remove the prefix text)\nlet newsletterContent = '';\nif (typeof aiOutput === 'object' && aiOutput.content) {\n newsletterContent = aiOutput.content;\n} else if (typeof aiOutput === 'string') {\n // Remove the \"this is the output from the ai agent:\" prefix if it exists\n newsletterContent = aiOutput.replace(/^this is the output from the ai agent:\\s*/i, '');\n} else {\n newsletterContent = JSON.stringify(aiOutput);\n}\n\n// Clean up the newsletter content - remove \\n literals and format properly\nnewsletterContent = newsletterContent\n .replace(/\\\\n/g, '\\n') // Convert literal \\n to actual newlines\n .replace(/^\\s+|\\s+$/g, '') // Trim whitespace\n .replace(/\\n{3,}/g, '\\n\\n'); // Replace multiple newlines with double newlines\n\n// Generate email subject with current date\nfunction generateEmailSubject() {\n const currentDate = new Date().toLocaleDateString('en-US', { \n year: 'numeric', \n month: 'long', \n day: 'numeric' \n });\n return `🤖 AI Weekly Pulse - ${currentDate}: ChatGPT Voice Update & Latest AI News`;\n}\n\n// Generate email body with proper formatting\nfunction generateEmailBody() {\n const emailBody = `Hi there!\n\nI hope this email finds you well. Here's this week's AI newsletter with the latest updates from the AI world:\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n${newsletterContent}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nHope you found this week's AI updates valuable! Feel free to reply with your thoughts or questions.\n\nBest regards,\nAI Weekly Pulse Team\n\n---\n📧 This newsletter was automatically generated and sent via n8n automation.\n🔗 Want to unsubscribe or have questions? Just reply to this email.`;\n\n return emailBody;\n}\n\n// Generate HTML version of the email for better formatting\nfunction generateHTMLEmailBody() {\n // Convert markdown-like content to basic HTML\n let htmlContent = newsletterContent\n .replace(/^# (.*$)/gm, '<h1 style=\"color: #333; border-bottom: 2px solid #667eea; padding-bottom: 10px;\">$1</h1>')\n .replace(/^## (.*$)/gm, '<h2 style=\"color: #444; margin-top: 30px; margin-bottom: 15px;\">$1</h2>')\n .replace(/^### (.*$)/gm, '<h3 style=\"color: #555; margin-top: 20px; margin-bottom: 10px;\">$1</h3>')\n .replace(/\\*\\*(.*?)\\*\\*/g, '<strong>$1</strong>')\n .replace(/\\*(.*?)\\*/g, '<em>$1</em>')\n .replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href=\"$2\" style=\"color: #667eea; text-decoration: none;\">$1</a>')\n .replace(/^- (.*$)/gm, '<li style=\"margin-bottom: 8px;\">$1</li>')\n .replace(/^> (.*$)/gm, '<blockquote style=\"border-left: 4px solid #667eea; padding-left: 20px; margin: 20px 0; font-style: italic; color: #666;\">$1</blockquote>')\n .replace(/---/g, '<hr style=\"border: none; border-top: 2px solid #eee; margin: 30px 0;\">')\n .replace(/\\n\\n/g, '</p><p style=\"line-height: 1.6; margin-bottom: 15px;\">')\n .replace(/\\n/g, '<br>');\n\n // Wrap list items in ul tags\n htmlContent = htmlContent.replace(/(<li[^>]*>.*?<\\/li>)/gs, '<ul style=\"padding-left: 20px; margin-bottom: 20px;\">$1</ul>');\n\n const htmlBody = `\n<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>AI Weekly Pulse</title>\n</head>\n<body style=\"font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 800px; margin: 0 auto; padding: 20px; background-color: #f9f9f9;\">\n <div style=\"background: white; padding: 40px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1);\">\n <div style=\"text-align: center; margin-bottom: 30px; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 8px; color: white;\">\n <h1 style=\"margin: 0; font-size: 24px;\">🤖 AI Weekly Pulse</h1>\n <p style=\"margin: 10px 0 0 0; opacity: 0.9;\">Your Weekly Dose of AI Innovation</p>\n </div>\n \n <div style=\"margin-bottom: 30px;\">\n <p style=\"font-size: 16px; color: #555;\">Hi there!</p>\n <p style=\"font-size: 16px; color: #555;\">Hope this email finds you well. Here's this week's AI newsletter with the latest updates from the AI world:</p>\n </div>\n \n <div style=\"background: #fafafa; padding: 30px; border-radius: 8px; margin: 20px 0;\">\n <p style=\"line-height: 1.6; margin-bottom: 15px;\">${htmlContent}</p>\n </div>\n \n <div style=\"margin-top: 40px; padding: 30px; background: #f0f4ff; border-radius: 8px; text-align: center;\">\n <p style=\"font-size: 16px; color: #555; margin-bottom: 15px;\">Hope you found this week's AI updates valuable!</p>\n <p style=\"font-size: 16px; color: #555; margin-bottom: 20px;\">Feel free to reply with your thoughts or questions.</p>\n <p style=\"font-size: 18px; color: #333; margin: 0;\"><strong>Best regards,<br>AI Weekly Pulse Team</strong></p>\n </div>\n \n <div style=\"margin-top: 30px; padding: 20px; background: #e8f2ff; border-radius: 8px; font-size: 14px; color: #666; text-align: center;\">\n <p style=\"margin: 5px 0;\">📧 This newsletter was automatically generated and sent via n8n automation.</p>\n <p style=\"margin: 5px 0;\">🔗 Want to unsubscribe or have questions? Just reply to this email.</p>\n </div>\n </div>\n</body>\n</html>`;\n\n return htmlBody;\n}\n\n// Generate the formatted output for the email node\nconst emailSubject = generateEmailSubject();\nconst emailBodyText = generateEmailBody();\nconst emailBodyHTML = generateHTMLEmailBody();\n\n// Return the formatted data for the next node (email sender)\nreturn [\n {\n json: {\n subject: emailSubject,\n text: emailBodyText,\n html: emailBodyHTML,\n // Additional metadata\n newsletter_content: newsletterContent,\n generated_at: new Date().toISOString(),\n email_type: \"ai_weekly_pulse\"\n }\n }\n];"
},
"typeVersion": 2
},
{
"id": "9a9676bb-d645-49fc-84ab-5a5c0cd92645",
"name": "AI 代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
280,
360
],
"parameters": {
"text": "=Newsletter Structure\n1. Title\nEngaging and punchy (under 10 words).\n\nIncludes a relevant keyword (e.g., “AI”, “ChatGPT”, “Machine Learning”).\n\n2. Editor’s Note (Optional but preferred)\nA short 2–3 sentence personal note to the readers.\n\nTone: Conversational and warm.\n\nSummarize the theme of this issue or highlight an AI trend to watch.\n\n3. 🧠 AI in Focus (Main Story)\nOne key development or trend in AI this week.\n\nCould be about a breakthrough, a major product launch, a regulatory move, or a case study.\n\n3–5 paragraphs long.\n\nInclude context (why it matters), impact, and your analysis.\n\n4. 📰 Headlines in AI (News Roundup)\nList 3–5 bite-sized headlines with 1–2 sentence summaries for each. Include:\n\nDate (optional).\n\nSource (e.g., OpenAI, Google, MIT, etc.).\n\nLink (if available).\n\nExample:\n\nOpenAI Releases GPT-5 Preview – OpenAI teased major upgrades in language understanding and reasoning. Read more\n\n5. 🔍 Tool of the Week\nIntroduce one new or underrated AI tool.\n\nInclude what it does, who it’s for, and how it works (2–3 sentences).\n\nInclude a link if available.\n\n6. 📚 Learning Corner\nRecommend one AI resource: a blog post, YouTube video, podcast, free course, or paper.\n\nMention why it’s worth reading/listening/watching.\n\n7. 🤖 Prompt of the Week\nShare a powerful or creative prompt users can try with ChatGPT or any LLM.\n\nExplain what it does and when to use it.\n\n8. 📈 AI Stat of the Week\nShare one interesting stat about AI.\n\nCite the source and explain the takeaway in 1–2 sentences.\n\n9. 👥 Community Shoutout (Optional)\nHighlight a person, open-source project, or discussion in the AI community.\n\n10. 👀 What to Watch Next Week\nPreview an upcoming event, release, or expected trend in AI.\n\nKeep it short (1–2 sentences).\n\n🧾 Style Guidelines\nUse markdown for formatting: **bold**, # headers, - lists, etc.\n\nKeep tone informative, clear, and slightly casual.\n\nAvoid jargon unless explained.\n\nUse bullet points and subheaders for readability.\n\nProvide citations for all the topics immediately ",
"options": {
"systemMessage": "You are an AI writing assistant tasked with creating a weekly newsletter about artificial intelligence (AI). The goal is to inform, engage, and educate readers ranging from tech-savvy professionals to curious enthusiasts. Follow the structure below and ensure the tone is professional yet accessible."
},
"promptType": "define"
},
"typeVersion": 1.9
},
{
"id": "4e5e19a9-b05f-4ef0-a432-a0e72c479095",
"name": "Azure OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
"position": [
260,
520
],
"parameters": {
"model": "gpt-4.1",
"options": {}
},
"credentials": {
"azureOpenAiApi": {
"id": "gDiLXmZSX0q3CyLu",
"name": "Azure Open AI account"
}
},
"typeVersion": 1
},
{
"id": "e7dbd62a-6580-4a28-ab85-5fdf885dacf0",
"name": "计划触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-140,
360
],
"parameters": {
"rule": {
"interval": [
{}
]
}
},
"typeVersion": 1.2
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "e0cf8d41-3776-4aab-a5ec-fd16b8bc7457",
"connections": {
"AI Agent": {
"main": [
[
{
"node": "Format Email Content",
"type": "main",
"index": 0
}
]
]
},
"Set Dates1": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Set Dates1",
"type": "main",
"index": 0
}
]
]
},
"Format Email Content": {
"main": [
[
{
"node": "Gmail1",
"type": "main",
"index": 0
}
]
]
},
"Azure OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 人工智能, 营销
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
AI YouTube 评论分析器
使用 GPT-4o 进行 YouTube 评论分析并通过 Gmail 发送自动邮件报告
If
Set
Code
+9
18 节点Rahul Joshi
人工智能
从Monday.com和Jira到Outlook的AI驱动反馈分类与报告
使用Azure GPT-4、Jira任务和Outlook报告分析来自Monday.com的客户反馈
Set
Code
Jira
+12
27 节点Rahul Joshi
自动化新闻到简报AI代理v13
AI新闻研究团队:24/7简报自动化,含Perplexity引用
Set
Code
Gmail
+15
37 节点Derek Cheung
产品
MailChimp自动化
基于AI的餐厅通讯生成器,集成Mailchimp和Telegram审批
If
Set
Code
+16
43 节点Femi Ad
人工智能
使用GPT-4o、WordPress和LinkedIn发布自动化RSS内容到博客文章
使用GPT-4o、WordPress和LinkedIn发布自动化RSS内容到博客文章
If
Set
Code
+21
40 节点Immanuel
人工智能
自动化博客撰写与社交媒体推广代理
使用GPT-4、Perplexity和WordPress自动化SEO博客创建+社交媒体
Set
Code
Gmail
+21
79 节点LukaszB
设计
工作流信息
难度等级
中级
节点数量8
分类2
节点类型7
作者
Rahul Joshi
@rahul08Rahul Joshi is a seasoned technology leader specializing in the n8n automation tool and AI-driven workflow automation. With deep expertise in building open-source workflow automation and self-hosted automation platforms, he helps organizations eliminate manual processes through intelligent n8n ai agent automation solutions.
外部链接
在 n8n.io 查看 →
分享此工作流