Tutorial: Automate Email Sending with OpenAI & Gmail in n8n

Watch the video

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:

:white_check_mark: Uses OpenAI to generate professional email content

:white_check_mark: Parses the email subject and body cleanly

:white_check_mark: 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.

:rocket: What You’ll Build

By the end of this tutorial, you’ll have a workflow that:

  1. Starts manually using the Manual Trigger node

  2. Uses OpenAI (Chat Model node) to generate a personalized email

  3. Parses the AI output into subject and body using a Set or Code node

  4. Connects to Gmail via OAuth2 authentication

  5. Sends the email using the Gmail → Send Message node

:puzzle_piece: Tools & Integrations Used

  • n8n (self-hosted or cloud)

  • OpenAI Node (ChatGPT or similar model)

  • Gmail Node

  • Google Cloud Console (to create Gmail OAuth2 credentials)

:locked_with_key: Setting Up Gmail in n8n (OAuth2)

To connect Gmail securely, follow these steps:

  1. Create a Google Cloud Project:

    Go to Google Cloud Console, create a new project.

  2. Enable Gmail API:

    Search for “Gmail API” and click Enable.

  3. Create OAuth2 Credentials:

  4. Copy the Client ID & Client Secret

    • Paste them into the Gmail credentials setup inside n8n

    • Authorize the connection and save

:blue_book: 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.

:open_mailbox_with_raised_flag: 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

:bullseye: Perfect For:

  • AI & automation beginners

  • Recruiters automating outreach

  • Developers testing n8n workflows

  • Marketers sending dynamic campaign emails

2 Likes