Watch on Youtube: https://www.youtube.com/watch?v=NJxkrfBuo8A
Tutorial: Automate Email Sending with OpenAI & Gmail in n8n
In this step-by-step tutorial, you’ll learn how to build a powerful automation workflow in n8n that:
Uses OpenAI to generate professional email content
Parses the email subject and body cleanly
Sends emails securely using the Gmail node with OAuth2 authentication
This is a perfect beginner-friendly project to get hands-on with AI-powered automation and real-world integrations.
What You’ll Build
By the end of this tutorial, you’ll have a workflow that:
-
Starts manually using the Manual Trigger node
-
Uses OpenAI (Chat Model node) to generate a personalized email
-
Parses the AI output into subject and body using a Set or Code node
-
Connects to Gmail via OAuth2 authentication
-
Sends the email using the Gmail → Send Message node
Tools & Integrations Used
-
n8n (self-hosted or cloud)
-
OpenAI Node (ChatGPT or similar model)
-
Gmail Node
-
Google Cloud Console (to create Gmail OAuth2 credentials)
Setting Up Gmail in n8n (OAuth2)
To connect Gmail securely, follow these steps:
-
Create a Google Cloud Project:
Go to Google Cloud Console, create a new project.
-
Enable Gmail API:
Search for “Gmail API” and click Enable.
-
Create OAuth2 Credentials:
-
Go to APIs & Services > Credentials
-
Click Create Credentials → OAuth client ID
-
Application type: Web Application
-
Add redirect URI: https://your-n8n-domain.com/rest/oauth2-credential/callback (For n8n Cloud, use the provided redirect URL from the Gmail node credential setup)
-
-
Copy the Client ID & Client Secret
-
Paste them into the Gmail credentials setup inside n8n
-
Authorize the connection and save
-
According to n8n Gmail Docs:
The Send Message operation supports plain text, HTML, and attachments, and you can dynamically populate the subject, recipient(s), and message content from previous nodes in the flow.
Sending the Email
-
Drag the Gmail node into your workflow
-
Set Operation to Send Message
-
Fill in fields:
-
To: Static email or from previous node
-
Subject: From OpenAI output
-
Text/HTML Body: From OpenAI output
-
-
Optional: Set cc, bcc, and even attach files from prior steps
Perfect For:
-
AI & automation beginners
-
Recruiters automating outreach
-
Developers testing n8n workflows
-
Marketers sending dynamic campaign emails
