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.
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
- Sign in to Activepieces Cloud.
- Open your project.
- Create a new flow.
- Name the flow AI Email Agent.

- Screenshot 1. New AI Email Agent flow in Activepieces
Step 3 – Add Gmail as the Trigger
- Click the Trigger block.
- Search for Gmail.
- Choose New Email.
- Connect the Gmail account you want the flow to monitor.
- 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. Thanks, |
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
- Click the + button below Gmail.
- Search for Google Gemini.
- Choose Generate Content.
- Connect Gemini using your Google AI Studio API key.
- 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: Assign one priority: Determine the sentiment: Write a short one-sentence summary of the email. Return ONLY this JSON structure: Sender: Subject: Email: IMPORTANT: |
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 |
| 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
- Click + below Gemini.
- Search for JSON.
- Choose Convert Text to JSON.
- In the JSON input, select the Output from Step 2 – Generate Content.
- Use the Activepieces data selector whenever possible instead of manually typing expressions.
- 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
- Click + below the JSON step.
- Search for Google Sheets.
- Choose Add Row.
- Connect the Google account that owns the AI Email Agent spreadsheet.
- Choose the AI Email Agent spreadsheet and Sheet1.
- 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.
- Click + below Google Sheets.
- Search for Gmail.
- Choose Create Draft Reply (or the closest Gmail draft-reply action available in your Activepieces version).
- Connect the same Gmail account used in the trigger.
- For the original message, map the message/thread data from Step 1 – New Email.
- For the reply body, map JSON -> suggested_reply.
- Keep automatic sending disabled.
- 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
- Click Publish in Activepieces.
- Make sure the flow toggle is ON.
- From a second email account, send a fresh email to the monitored Gmail inbox.
- Wait for the trigger to pick up the email.
- Open Runs in Activepieces.
- Confirm each workflow step succeeds.
- Open Google Sheets and confirm a new row is created.
- Open Gmail Drafts and verify the AI-generated draft reply.
| Example real test email
Subject: Urgent: Unable to access my account Hi, Thanks, |

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.