Animated data flow diagram

AI Email Auto-Responder & Feedback Logger with OpenAI & Google Sheets

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

OpenAI Gmail Google Sheets

Overview

Unlock Automated Email Management & AI Improvement with this AI Agent

This n8n AI Agent listens for incoming Gmail messages from specified recipients, crafts intelligent replies using OpenAI, and sends them automatically. Crucially, it logs the original email, the AI-generated response, and any user feedback (via clickable links in the reply) to a Google Sheet. This creates a valuable dataset for analyzing AI performance and for future fine-tuning of your language models. If a Google Sheet isn't specified or found, the agent will create one for you.

Key Features & Benefits

  • AI-Powered Reply Generation: Leverages OpenAI's language models to generate context-aware email replies.
  • Automated Email Handling: Triggers on new Gmail messages and sends replies without manual intervention.
  • Selective Processing: Configurable to only process emails from specific senders or if you are the recipient.
  • Conversation & Feedback Logging: Automatically records the initial message, AI reply, and user feedback ('Yes'/'No' on helpfulness) to a Google Sheet.
  • Data for AI Fine-Tuning: The logged data serves as a perfect foundation for fine-tuning custom AI models.
  • Dynamic Google Sheet Management: Creates a new Google Sheet for logging if one isn't specified or found, and populates headers.
  • Token-Aware Processing: Checks if the email content is within OpenAI token limits before processing to prevent errors and manage costs.
  • User Feedback Loop: Includes simple "Was this helpful?" links in replies, which trigger a webhook to log feedback directly into the corresponding row in Google Sheets.

Use Cases

  • Automating first-contact responses for sales or support inquiries.
  • Building a dataset of email interactions and AI performance for model training.
  • Gathering explicit user feedback on AI-generated content to improve response quality.
  • Streamlining communication with predefined contacts using AI assistance.
  • Creating an archive of AI-assisted email exchanges for quality assurance and knowledge base generation.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • OpenAI API Key with access to a suitable model (e.g., gpt-3.5-turbo, gpt-4).
  • Gmail credentials (OAuth2 set up in n8n for both triggering and sending emails).
  • Google Sheets credentials (OAuth2 set up in n8n for logging data).
  • If self-hosting n8n, your n8n instance must be publicly accessible via a Webhook URL (e.g., for the feedback links to work). You'll need to set the WEBHOOK_URL environment variable for your n8n instance (e.g., https://your-n8n-domain.com/).

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Configure the 'On email received' (Gmail Trigger) node: Select or create your Gmail OAuth2 credentials.
  4. Configure the 'Send reply to recipient' (Gmail) node: Select or create the same Gmail OAuth2 credentials used in the trigger.
  5. Configure the 'Generate reply' (OpenAI) node: Enter your OpenAI API Key and select your desired model. Adjust maxTokens in the 'Options' section as needed.
  6. Configure all 'Google Sheets' nodes ('Create spreadsheet', 'Paste data', 'Create or update rows', 'Send feedback for fine-tuned data'): Select or create your Google Sheets OAuth2 credentials.
  7. Review and update the 'Configure' node:
    • recipients (string): Comma-separated list of email addresses that will trigger a reply. Use * to process all incoming emails that are replies to your address (use with caution). Alternatively, set it to your email address to reply to emails sent from specific senders based on the Only continue for specific emails node logic (which you might need to adjust).
    • spreadsheetName (string, required): The human-readable name for the Google Sheet if it needs to be created.
    • worksheetName (string, required): The human-readable name for the worksheet within the spreadsheet.
    • spreadsheetId (string, optional): If you want to use an existing Google Sheet, provide its ID here. Ensure it has columns: 'ID', 'Initial message', 'Generated reply', 'Good response?'.
    • worksheetId (string, optional): If using an existing spreadsheet, provide the specific worksheet ID.
    • maxTokenSize (number, required): Maximum tokens for the OpenAI model (context + reply).
    • replyTokenSize (number, required): Maximum tokens allocated for the OpenAI reply.
  8. Verify Webhook URL for Feedback: The 'Email template' node uses {{ $env.WEBHOOK_URL }} to construct feedback links. If self-hosting, ensure this environment variable is correctly set for your n8n instance. For n8n Cloud, this is usually handled automatically.
  9. Activate the workflow. The Gmail trigger will poll for new emails according to its schedule, and the webhook will be active to receive feedback.

Tags:

AI AgentEmail AutomationOpenAIGmailGoogle SheetsFeedback LoopAI Fine-tuningCustomer SupportProductivity

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation