How I use n8n and agentic AI to manage my gmail

In an age where managing vast amounts of email can be overwhelming, I turned to n8n and Generative AI (Open AI API) to automate my Gmail workflow. This article explores my journey in creating an efficient system that helps me stay on top of my personal inbox without sacrificing quality.

The motivation behind automating my Gmail

Ever been stuck on the bus and need to write an important email, but typing the message on your phone doesn’t work?
Ever miss an email that got buried in the dirge of promotions for websites you don’t remember subscribing to?
Ever responded emotionally to a sensitive email, without considering other perspectives?

The motivation behind automating my Gmail management stemmed from my desire for efficiency in communication. Like many, I grapple with a flooded inbox, and in the chaos, key messages often slip through the cracks. The impact was not just about time; it affected relationships and opportunities. I realised that responding promptly to important emails could significantly enhance my personal and professional life.

Facing the daily overwhelm of emails was like trying to navigate through a dense fog—each message vying for attention but obscured by numerous distractions. I had a persistent worry that a critical email might get lost in the shuffle, leaving necessary inquiries or opportunities unanswered. This realisation led me to seek a solution that would allow me to manage my emails intelligently.

The promise of automation stood out for its potential to streamline my workflow. I envisioned a system where emails could be categorised and prioritised swiftly, allowing me to focus on crafting thoughtful responses without losing essential correspondence. Through n8n and generative AI, I aimed to strike a balance between automation and personal touch, responding quickly without compromising the quality or relevance of my communications.

To ensure that the automation process met my standards, I designed it to draft responses rather than send them outright. This approach allowed me to maintain control over the content, making personalised tweaks where necessary. My testing revealed promising results: the initial classification of emails was rated at 9/10, indicating that the system could efficiently identify critical messages. However, the drafting quality was slightly lower at 7/10, highlighting the ongoing need for my input to make each message resonate authentically.

This journey of automating my Gmail was fueled by a desire to enhance my productivity while recognising the irreplaceable human touch in meaningful communications. By strategically leveraging technology, I aimed to create a more efficient and responsive email management system that catered to my personal and professional needs.

How I built the n8n workflow

(This looks better on a bigger screen)

High Level Overview

  • My primary goal was to improve my response time to critical emails while ensuring I did not lose the personal touch in my communications.
  • Building a n8n Workflow involves a systematic, methodical approach to creating a robust automation system tailored to the use case.
  • In n8n, the logical process flows from left to right sequentially or in parallel.
  • Once built, tested and I was happy with it, I activated the workflow and it is automatically triggered with each new email that I receive
  • I used quite a few AI Agents/node: For all I used Open AI API with GPT-4o-mini
  • Rough Process:
    • Trigger: When I receive a new email
    • Email Classifier: Figuring out what type of email it is
    • Sentiment Analysis AI Agent: Is the “vibe” of the email positive, neutral or negative?
    • Email Agent: Use Open AIs API and the content to respond to the email
    • Gmail API: Create a Draft for me to review
    • Analysis & Summary AI agent: When a critical email is negative, analyse the content and brainstorm a strategy on how to respond
    • Diplomatic Email Agent: Take the advice from the analysis agent to craft a well-reasoned response
    • For emails tagged as “Promotions” or “Newsletters”: Here I use the Gmail API to mark the emails as read
    • For “Financial, tax” emails: These get a Gmail tag “Financial”
  • I’ll cover the main points in the slides to the right:

Text Classifier

  • Next, I used n8n’s text classifier node.
    • This node (with the connected LLM model) takes three inputs: Google’s labels.
    • Name and email address
    • The email’s subject
    • The contents of the email
    • Then, I predefined the following categories:
    • Critical: Emails that require immediate attention due to their urgency or importance. These typically include urgent security alerts, emergency notifications, account verification emails, password reset requests, legal notices, or any time-sensitive communications that could have serious consequences if ignored.
    • Promotions & Discounts: Emails containing promotional offers, sales announcements, discount codes, or limited-time deals from businesses and retailers. These emails typically aim to encourage a purchase and often include phrases like “Limited-time offer,” “Exclusive discount,” or “Sale ends soon.”
    • Newsletters & Subscriptions: Periodic emails from publications, blogs, organizations, or mailing lists that provide updates, news, industry insights, or personal interest content. These often contain long-form articles, company updates, or curated news from subscribed services.
    • Financial & Billing Emails: Emails related to financial transactions, billing, and account statements. This includes invoices, receipts, bank statements, payment confirmations, tax-related documents, and subscription billing notifications.
    • Other: Everything else

Sentiment Analysis

  • n8n’s sentiment analysis node works in the same way as the text classifier:
    • Set up your LLM API
    • The tool then has some basic configuration options in the context of sentiment analysis.
    • I am even providing the same inputs as before: From, subject and contents
  • In this case, I only really need a fundamental analysis for Positive, Neutral, and Negative

Positive Sentiment: Email Agent

  • I have set up another agent with a specific system prompt here. The idea here:
  • Alongside setting the typical role, task and instructions, I included a couple of key quality-of-life concepts
    • Give me two answers in the draft so that I can choose which suits
    • Dont make-up content; leave a placeholder instead
  • This makes the draft much easier to edit once it’s created
  • Here is the prompt I used:
You're a helpful personal assistant and your task is to draft replies on my behalf to my incoming emails. Whenever I provide some text from an email, return an appropriate draft reply for it and nothing else.
Ensure that the reply is suitable for a professional email setting and addresses the topic in a clear, structured, and detailed manner.
Do not make things up.

Detailed instructions:
- Be concise and maintain a business casual tone.
- Start with "Hello,", and end with "Cheers,"
- When replying to yes-no questions, draft 2 responses: one affirmative and one negative separated by " - - - - - - - OR - - - - - - - "
- If you don't know an answer, you can leave placeholders like "[YOUR_ANSWER_HERE]".
- Don't use any special formatting, only plain text.
- Reply in the same language as the inbound email.

Negative Sentiment: Analysis AI Agent

  • The first step to reply to a “Negative” email is to use a custom AI agent to analyse the content of the email and generate some ideas about why
  • Here is the prompt that I used:
Prompt:  *"You are my AI assistant, analysing negative or emotionally charged emails in my personal inbox. Your job is to understand the sender's concerns, detect their emotional state, and summarise the issue in a way that helps me decide how to respond.  

Instructions: Analyse the email and extract the following details:
- Summary of Concerns: What is the sender upset, frustrated, or negative about? Tone & Sentiment: Identify the emotional tone (e.g., annoyed, disappointed, angry, passive-aggressive, guilt-tripping). Urgency Level: Does this email require an immediate - --- response (High), a response when convenient (Medium), or can it be ignored/deprioritised (Low)?
- Personal Relationship Context: Is this from a friend, family member, acquaintance, or unknown sender? Key Requests or Expectations: What does the sender want from me (an apology, explanation, action, reassurance, etc.)?
- Suggested Next Steps: Should I respond? If so, what approach is best—acknowledge, de-escalate, set boundaries, clarify misunderstandings, or ignore?

Output Format (Plain Text Only):
- Summary of Concerns: [Brief issue summary]
- Tone & Sentiment: [Emotional state detected]
- Urgency Level: [High/Medium/Low]
- Personal Relationship Context: [Friend/Family/Acquaintance/Unknown]
- Key Requests or Expectations: [What they want]
- Suggested Next Steps: [Recommended response strategy]"*

Negative Sentiment: Diplomatic AI Agent

  • The 2nd step to reply to a “Negative” email is to use the previous agent’s understanding of the potential issue
  • In this case, I provide some examples for better One-shot responses
  • Here is the prompt that I used:
Prompt:
*"You are my AI assistant, helping me craft thoughtful responses to negative or emotionally charged emails in my inbox. You aim to create a respectful, appropriate reply to the relationship and be emotionally intelligent while ensuring I maintain my boundaries.

Guidelines:
- Tone: Adapt the tone based on the sender (casual for friends, polite but firm for acquaintances, empathetic for family, neutral for unknown senders).
- Acknowledge but Don't Over-Apologize: Recognize concerns, but avoid excessive apologies unless necessary.
- Set Boundaries If Needed: If the sender is unreasonable, pushy, or guilt-tripping, craft a polite but firm response.
- Keep It Brief & Clear: Avoid over-explaining or justifying—keep the reply concise.
- Offer a Resolution or Closure: Suggest how to move forward if appropriate. Return a polite but disengaging message if the situation doesn't require a response.

Format:
- Begin with "Hey [Name]" (or "Hello," if more formal is needed)
- Use a tone that matches the relationship and situation.
- Address their concern briefly, then state my position.
- If needed, include a polite closure that ends the conversation naturally.
- End with "Cheers" or "Kind Regards," depending on context.

Example Input from Analysis Node:
- Summary of Concerns: A friend is upset that I haven't replied to their messages.
- Tone & Sentiment: Annoyed but not aggressive.
- Urgency Level: Medium.
- Personal Relationship Context: Friend.
- Key Requests or Expectations: Wants reassurance and a response.
- Suggested Next Steps: Acknowledge the delay and respond casually but warmly.

Example AI-Generated Response:
"Hey [Friend's Name],
Sorry for the delay in responding. I've been caught up with a few things. I really appreciate your patience. Let's catch up soon! I hope you're doing well.
Cheers,
Keagan Deasy"

Quality Control in Automated Responses

Maintaining the quality of my automated email responses is essential for two reasons:

  • The original goal was to save me time, and that is mitigated if I have to rewrite the whole draft
  • Also, there is enough Gen AI trash out there; I don’t need to add more to it

While integrating n8n and Generative AI allows for significant efficiency gains, there will always be concerns when using the current. My approach is centred on creating drafts with the automated system while reserving the final touch for manual review.

Here’s how I maintain quality control in my automated responses:

  • Draft-Only Approach: The automation generates an email draft rather than sending responses directly. This structure allows me to review and personalise the content before it reaches the recipient, ensuring that my voice and intent are represented.
  • Personalisation Requirement: I maintain a connection with my recipients by requiring manual input for personalisation. While automation handles the foundational drafting, I can tailor details that matter, making each response sound authentically “me.”
  • Testing and Spot Checks: I routinely test the drafting outputs. This includes reviewing randomly selected drafts to assess clarity, tone, and appropriateness. Spot-checking helps identify recurring issues and refine the AI’s understanding of my preferences.
  • Iteration: When I do find issues or strange wording, n8n makes it very easy to make changes and redeploy

I found a balance between efficiency and personal touch through this hybrid approach. Here is my assessment of the quality of the current iteration:

  • My classification accuracy for incoming emails stands impressively at 9/10
  • Meanwhile, my email drafting quality currently stands at 7/10.
    • I will likely need to use an LLM model with more input tokens and polish my prompts.

Ultimately, this method secures the necessary oversight while still benefiting from automation’s speed, preserving communication quality without sacrificing efficiency. Maintaining this balance has significantly enhanced my email management experience, making it a productive collaboration between human insight and AI efficiency.

Findings from the Automation Experience

  • Utilising n8n and Generative AI for my Gmail management yielded remarkable results that transformed my email workflow.
  • Regarding drafting responses, the quality was rated at 7/10. While the AI-generated drafts effectively covered the essential points, they often required my touch to sound more personalised and reflect my style. Key details, such as tone and specific context, frequently needed to be added manually.
  • What worked well was the ability to trigger this automation based on incoming emails, allowing me to respond more quickly without missing critical messages. The AI sentiment analyser also played a crucial role in how I handled urgent replies—if an email was flagged as positive or neutral, a relevant draft was generated. In cases of negative sentiment, the system provided insightful feedback, enhancing my response strategy.
  • However, challenges remain. The categorisation of non-critical emails is still a work in progress, and further refinements are needed for more nuanced classifications.
  • Overall, this automation experience has significantly enhanced my email management effectiveness, allowing for quicker responses while ensuring I retain control over the quality of my correspondence.

Future Implications and Further Automation

The future of my email management workflow is ripe with potential, especially as advancements in Generative AI and automation technologies continually reshape the landscape. As I refine my current setup, I envision several enhancements that could significantly boost efficiency and personalisation.

  • Firstly, further integrations could be implemented. For instance, incorporating project management tools like Trello or Asana could help align email correspondence directly with ongoing projects. Automatically generating tasks from emails, or even creating follow-up reminders based on email threads, could further streamline my workflow.
  • Additionally, improving classification algorithms remains a focal point. While my current system already segments emails into critical categories, expanding the granularity of these classifications could enhance focus. For example, introducing subcategories for important contacts or project-specific emails could facilitate quicker access and improved prioritisation.
  • Moreover, as sentiment analysis improves, the capability to interpret emotions more accurately will enhance draft writing. Imagine an AI that can detect urgency or frustration, allowing it to tailor responses precisely. For critical emails with negative sentiment, offering resolutions and follow-up suggestions can significantly improve the communication experience.
  • Lastly, I foresee benefits from ongoing user feedback loops where I regularly contribute insights about draft quality. This continuous learning approach will empower the AI to adapt better to my style, increasing the quality of drafting over time.


As these advancements materialise, the overarching goal remains to increase my efficiency while retaining an authentic and personalised touch in my communications. This alignment of improved technology and human oversight promises a future where managing emails becomes an effortless, highly effective endeavour.

Conclusions

The integration of n8n with Generative AI significantly improved my email management process. While automation enhances speed and classification accuracy, maintaining a personal touch in email responses remains crucial. This experience highlights the potential of technology while reminding us of the importance of human oversight.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top