n8n Tutorial: Build an AI Workflow to Extract Top Insights From All Your Newsletter Emails
Stop drowning in newsletter overload—get the best takeaways from all your emails in one weekly digest
Dear subscribers,
Today, I want to share how to build an AI workflow to summarize newsletter emails.
I get about 15 newsletters a week, and this workflow extracts the top 3 takeaways from each one and sends me a weekly digest every Sunday.
It feels a little weird writing this since you’re reading a newsletter right now 😅 But my goal is to save you time and give you hands-on practice for n8n, one of the most popular AI workflow platforms out there. Here's what we'll build together:
Tag newsletters in Gmail and connect n8n
Set up a weekly trigger to fetch newsletters
Aggregate and clean all newsletter content
Create an AI prompt to generate your digest
Format and email your weekly summary
I wrote this post with Alex, an expert at building AI workflows. Get her free AI agent checklist with 10 more ways to use workflows and agents to automate your business.
What is n8n and why use it?
n8n is a workflow automation tool that serious AI builders swear by. It looks intimidating at first but becomes surprisingly intuitive once you dive in.
Here's what we'll build from scratch:
Don't worry if this looks complicated. We'll build it step by step.
If you get stuck, just ask AI for help
Quick note before we start:
n8n is more complex than the Zapier AI workflow that I covered last week. If you get stuck, paste this whole post into ChatGPT and ask for help on a specific step.
For example, here I’m asking ChatGPT to write code to format my email better:
The point is to stay persistent and not give up, that’s how you learn AI. 🔥
Step 1: Tag newsletters in Gmail and connect n8n
First, we need clean data to work with.
Go to Gmail and create a label called Newsletter. Then apply this label to your emails manually or set up Gmail filters to tag specific senders:
This step matters. The cleaner your data, the better your digest will be.
Next, create an n8n account and connect it to Gmail:
Create an n8n account. Go to n8n and sign up for the 14-day free trial. The 2,500 monthly workflow executions will give you plenty of room to build and test.
Connect Gmail to n8n. From the n8n Overview page, click the dropdown on the orange Create Workflow button and select Create Credential.
Type "Gmail" in the search bar, click Continue, then Sign In with Google. Hit Save.
Optional: Get your OpenAI API key. As of this writing, n8n gives you free OpenAI credits. But you can also go to platform.openai.com to get your own API key.
Step 2: Set up a weekly trigger to fetch newsletters
Go back to the n8n Overview page and click "Create Workflow." Click Add first step and add the trigger On a schedule. Configure it like this:
Trigger interval: Weeks
Weeks between triggers: 1
Trigger on Weekdays: Sunday
Hour: 7 (for 7 AM)
This tells your workflow to run every Sunday morning at 7 AM. Next, on your workflow page, add a Gmail node after the trigger by clicking the "+" button and searching for "Gmail." Select "Get many messages" and configure:
Credentials: Select the Gmail account you added earlier
Resource: Message
Operation: Get Many
Return all: Toggled on
Simplify: Toggled off
Filters: Add a Search filter and type in: label:newsletter AND newer_than:7d
This grabs all emails with the Newsletter label from the past 7 days. Your workflow should look now look like this:
Hit "Execute workflow" and double-click the "Get many messages" node to see if the right newsletter emails are coming through. You'll see lots of metadata too, so don’t be alarmed.
Step 3: Aggregate and clean all newsletter content
Add an "Aggregate" node after the Gmail node to combine all your newsletter content into one chunk for AI to process. Configure it as follows:
Aggregate: All Item Data (Into a Single List)
Put Output in Field: data
Include: All fields
Hit "Execute step" to test the node.
Sometimes you'll pull too many emails for OpenAI to process. Add a "Code" node after your Aggregate node and name it "Truncate emails." In the Javascript field, paste this code to truncate the emails to 100K characters:
return [
{
json: {
truncated: JSON.stringify(items, null, 2).slice(0, 100000)
}
}
];
Hit "Execute step" to make sure the output works. Your workflow should now have four connected nodes:
Step 4: Create an AI prompt to generate your digest
This is where the magic happens. Click "+" after the Code node and search for "AI Agent." Configure it as follows:
Source for Prompt: Define below
Prompt (User Message): Drag and drop the input field on the left into this field.
Now click "Add Option" and select "System Message." This is where you write your AI prompt. Here's my detailed prompt to get a clean digest with 3 top takeaways for each newsletter: