← Back to tutorials
AI Image Generators

How to Build an AI Email Agent with Activepieces, Gmail, Google Sheets and Gemini

Build a smart AI Email Agent using Activepieces, Gmail, Google Sheets, and Gemini. This hands on guide shows you how to automatically analyze incoming emails, classify priority and sentiment, log results in Google Sheets, and generate draft replies without writing any code.

Written byAyushi Jha
PublishedSep 3, 2026
Reading time7 min
Views1.2K
How to Build an AI Email Agent with Activepieces, Gmail, Google Sheets and Gemini

Email triage is repetitive: every incoming message has to be read, understood, prioritized, summarized, and often replied to. In this hands-on, we automate that workflow using Activepieces and Google Gemini. The final flow watches Gmail, sends the message to Gemini for analysis, converts the AI response into structured JSON, writes the result into Google Sheets, and creates a Gmail draft reply for human review.

Outcome: Every new email can be classified, prioritized, summarized, logged, and turned into a ready-to-review draft without writing code.

What the agent will do

  • Detect a new email in Gmail.
  • Read the sender, subject, and email body.
  • Classify the email into Sales, Support, Collaboration, General, or Spam.
  • Assign High, Medium, or Low priority.
  • Detect Positive, Neutral, or Negative sentiment.
  • Generate a one-sentence summary.
  • Generate a professional suggested reply.
  • Add all structured information to Google Sheets.
  • Create a Gmail draft reply for human review.

Tools and accounts required

Tool Purpose
Activepieces Visual no-code automation builder
Gmail Incoming email trigger and draft reply
Google Gemini Email understanding and response generation
Google AI Studio Gemini API key
Google Sheets Structured email log
Second email account Real-world testing

Before you start

Security note: Use a test or non-critical inbox while building. Do not expose API keys in screenshots. Keep AI-generated replies as drafts until the workflow has been thoroughly tested.

Step 1 – Prepare the Google Sheet

Create a new Google Sheet and name it AI Email Agent. In the first row, add these headers in the same order:

Date Sender Subject Category Priority Sentiment Summary Suggested Reply
Why this matters: The column names become the destination fields that Activepieces will fill later.

Step 2 – Create a New Flow in Activepieces

  1. Sign in to Activepieces Cloud.
  2. Open your project.
  3. Create a new flow.
  4. Name the flow AI Email Agent.

  1. Screenshot 1. New AI Email Agent flow in Activepieces

 Step 3 – Add Gmail as the Trigger

  1. Click the Trigger block.
  2. Search for Gmail.
  3. Choose New Email.
  4. Connect the Gmail account you want the flow to monitor.
  5. Keep optional filters empty for the first test unless you specifically want to restrict which emails are processed.

         Screenshot 2. Gmail – New Email trigger configuration

 Step 4 – Test the Gmail Trigger

From another email account, send a test message to the Gmail account connected in Activepieces. You can use the following example:

Subject: Need help with my subscription

Hi,

I purchased your Pro plan yesterday but I am unable to access the premium features.
Could you please help me resolve this issue?

Thanks,
Rahul

Return to Activepieces and test the Gmail trigger. The output should contain fields such as sender, subject, date, HTML/body content, message, and thread. Once this works, downstream steps can use those values.

Step 5 – Add Google Gemini

  1. Click the + button below Gmail.
  2. Search for Google Gemini.
  3. Choose Generate Content.
  4. Connect Gemini using your Google AI Studio API key.
  5. Choose an available general-purpose model. In our build, Gemini 2.5 Flash was used.

Screenshot 4. Google Gemini – Generate Content step

Step 6 – Add the Email Analysis Prompt

Paste the following prompt into the Gemini prompt field. This prompt forces Gemini to return a predictable structure that can be used by later automation steps.

You are an AI email assistant.

Analyze the following incoming email.

Classify it into exactly one category:
Sales
Support
Collaboration
General
Spam

Assign one priority:
High
Medium
Low

Determine the sentiment:
Positive
Neutral
Negative

Write a short one-sentence summary of the email.
Then write a concise and professional suggested email reply.
Do not invent information that is not present in the email.

Return ONLY this JSON structure:
{
“category”: “”,
“priority”:   “”,
“sentiment”: “”,
“summary”: “”,
“suggested_reply”: “”
}

Sender:

Subject:

Email:

IMPORTANT:
Return ONLY raw JSON.
Do not use Markdown.
Do not use code fences.
Do not write “`json.
Do not add any explanation before or after the JSON.
The first character of your response must be {
and the final character must be }.

Step 7 – Map Gmail Data into the Prompt

Do not leave placeholder words such as EMAIL_SENDER, EMAIL_SUBJECT, or EMAIL_BODY in the prompt. Use the Activepieces Data Selector to insert the actual Gmail fields:

Prompt field Select from Step 1 – New Email
Sender From text
Subject Subject
Email HTML or another field containing the full email body

Figure 3. Gmail Sender, Subject, and Email fields mapped into Gemini

Step 8 – Test Gemini

Click Retest Step. The output should begin directly with { and end with }. A valid response looks like this:

{
“category”: “Support”,
“priority”: “High”,
“sentiment”: “Neutral”,
“summary”: “The customer cannot access premium features after purchase.”,
“suggested_reply”: “Hi Rahul, thank you for reaching out. We will review the issue and help you resolve it as soon as possible.”
}

Step 9 – Convert Gemini Text into JSON Fields

  1. Click + below Gemini.
  2. Search for JSON.
  3. Choose Convert Text to JSON.
  4. In the JSON input, select the Output from Step 2 – Generate Content.
  5. Use the Activepieces data selector whenever possible instead of manually typing expressions.
  6. Test the step.
Important: Choose Convert Text to JSON – not Convert JSON to Text.

Figure 5. Convert Text to JSON tested successfully

After a successful test, the AI output becomes individual fields that can be selected separately: category, priority, sentiment, summary, and suggested_reply.

Step 10 – Add Google Sheets

  1. Click + below the JSON step.
  2. Search for Google Sheets.
  3. Choose Add Row.
  4. Connect the Google account that owns the AI Email Agent spreadsheet.
  5. Choose the AI Email Agent spreadsheet and Sheet1.
  6. Turn on First Row Contains Headers.

Screenshot 5. Google Sheets – Add Row basic configuration

12. Step 11 – Map Sheet Columns

Map the row values as follows:

Google Sheet column Value from Activepieces
Date Gmail -> Date
Sender Gmail -> From text
Subject Gmail -> Subject
Category JSON -> category
Priority JSON -> priority
Sentiment JSON -> sentiment
Summary JSON -> summary
Suggested Reply JSON -> suggested_reply

Figure 6. Mapping Gmail and AI values into the Google Sheets row

Step 12 – Test Google Sheets

Click Test Step and then open the spreadsheet. A new row should appear automatically. Check that Category, Priority, Sentiment, Summary, and Suggested Reply are in their own columns rather than being stored as one large JSON string.

Figure 7. Successful row added to Google Sheets

Step 13 – Create a Gmail Draft Reply

To complete the AI Email Agent, add one final Gmail action that creates a draft reply instead of sending the AI response automatically.

  1. Click + below Google Sheets.
  2. Search for Gmail.
  3. Choose Create Draft Reply (or the closest Gmail draft-reply action available in your Activepieces version).
  4. Connect the same Gmail account used in the trigger.
  5. For the original message, map the message/thread data from Step 1 – New Email.
  6. For the reply body, map JSON -> suggested_reply.
  7. Keep automatic sending disabled.
  8. Test the step and check Gmail -> Drafts.

Screenshot 6. Gmail Create Draft Reply configuration

Why a draft? A human can review tone, facts, pricing, promises, and sensitive content before sending. This is the safer first production version.

 Step 14 – Publish and Run a Real Test

  1. Click Publish in Activepieces.
  2. Make sure the flow toggle is ON.
  3. From a second email account, send a fresh email to the monitored Gmail inbox.
  4. Wait for the trigger to pick up the email.
  5. Open Runs in Activepieces.
  6. Confirm each workflow step succeeds.
  7. Open Google Sheets and confirm a new row is created.
  8. Open Gmail Drafts and verify the AI-generated draft reply.
Example real test email

Subject: Urgent: Unable to access my account

Hi,
I made the payment yesterday but I am still unable to access my account.
Could you please resolve this issue as soon as possible?

Thanks,
Rahul

Figure 8. Successful real run: Gmail -> Gemini -> JSON -> Google Sheets

Success check: A complete run should show green/succeeded states for every configured step. If the Gmail draft step was added after this screenshot, capture one final run including that step for the published article.

What Happens Behind the Scenes

The Gmail trigger supplies the raw email. Gemini performs language understanding and generates structured analysis. The JSON step converts that response into individual fields. Google Sheets stores the result, while Gmail turns the suggested_reply field into a reviewable draft.