I built a Free Gmail Automation with ChatGPT and Google Apps Script
(No API Quotas or Subscriptions Required)
I built a Free Gmail Automation with ChatGPT and Google Apps Script
(No API Quotas or Subscriptions Required)

This free workflow saves me 1 hour per day, probably. Thanks, Google + ChatGPT :)
🥕 This short guide will show you what ChatGPT Prompts I used to automatically clean my Gmail account automatically every 30 minutes. I consider it a “mental health tool” which reduces digital clutter in my life.
🥕 If you just want to view the code, scroll to the bottom for the github link! That said, I recommend that you write your own version so you can learn how to use ChatGPT to code for you.
Problem to Solve
I spend way too much time cleaning up Spam and Marketing Emails. This automation will give you a powerful “Rule Engine” spreadsheet to automatically mark emails as read and archive them.
Other Benefits
- Neuroscience says that Mental load & spam will reduce your cognitive capacity over time: With many emails (junk + legit) coming in, your brain’s filter is being taxed. Overload reduces the ability to spot weird or malicious email… or simply is a waste of time.
- In Gmail, you can click “Unsubscribe” or Create Filters, but before long you’ll realize that it’s a battle that you’re wasting a lot of clicks to do this manually.
- Writing your email filters from a spreadsheet is WAY FASTER 🙂
- If you can control your attention, you can control your destiny!
Alternatives considered
Nowadays because of the AI bubble, there are paid services like Unroll.Me, Make, and Agentic AI apps, but I can barely afford eggs, so I created this free solution for myself and Gmail users.
If you use Outlook, check out Power Automate, but today I’ll be focusing on using Google Apps Script Gmail automation to get the job done.
You can also hire someone from Fiverr to code this for you, if you can write a nice PRD and time and money to spare.
Okay, let’s get to business…
Set up steps
Create a Google Spreadsheet, which will be where you maintain your “Email Rule Engine”

Your spreadsheet will have three separate “sheets” or tabs with these columns:
Sheet 1: Email Actions Tab
Date Time, Action Taken, Email Subject, Rule / Reason Action Taken
Sheet 2: Rules Tab
Rule Number, Rule Condition Contains
Sheet 3: ChatGPT Prompt Tab
Just for reference, I like to put my original “One shot” GPT Prompt below” in any of my Google Sheets based projects:
Write me a Google Apps Script that will automatically Archive and Mark As Read emails so I dont have to read them at all.
It should be limited to just the last 7 days of emails. Then send me a summary of all of the emails I sent, categorized in some thoughtful way, with the ability to preview the subject lines. Perhaps putting it in a webapp somehow.
It will use a Google Sheet as its backend. Spreadsheet Name: Gmail Virtual Assistant App Sheet URL: {{INSERT YOUR GOOGLE SHEET URL}}
Sheet column format is as follows:
Date Time Action Taken Email Subject Rule / Reason Action Taken
ChatGPT Magic Moments
Once prompted, GPT gave me the fully built out code and explained how to set everything up, including Security and Trigger Setup steps

💡 If you’ve never created Apps Script before, from your Spreadsheet, click Extensions > Apps Script to add. You will see Code.gs and that’s the file that GPT is asking you to create. Create the separate HTML files from the Google Apps Script GUI as well.

Implementing the Rule Engine
It did what I asked pretty well, but it’s missing additional logic, which is to check my Rule Engine for what emails to filter out.

I needed to refine the code with this prompt:
Add a new requirement to the existing code. Instead of auto-archiving all messages, Use the Sheet Tab called, Rules, to determine if the email should be archived.
Rule Number Rule Condition Contains 1 LinkedIn Job Alerts 2 danphamsslack.slack.com 3 unsubscribe 4 We noticed a new sign-in to your Google Account on a Linux device 5 OnePay is a financial technology company
How it works: Basically, if the email author or email body has the string listed in Column B, then it should get archived.
This made it so that my Rule Engine will only take action on the emails I want it to.
The rest of the emails will remain unread for me to look at during my regular email checking times.
Adding Logging / Debugging
Ran into some bugs. Let’s ask ChatGPT to fix.
When I run autoArchiveLast7Days, it seems to hang. Can you add some logging

ChatGPT gives me “Drop in” code, which lets me replace specific formulas. Pretty nifty.
Google Apps Script: Setting it to run every 30 minutes
Apps Script lets you program this with a GUI pretty easily.
This step is very important, because this means I am no longer using my “cognitive load” to check emails.

You can set triggers to run once a day, or multiple times a day, or during specific dates and times.
✅ Results
After a week, my inbox dropped significantly, probably from 1,200 emails to 140 :) And because of my Rule Engine, I didn’t miss a single important message.
More importantly, my brain feels quieter. I can actually focus again.
“Roadmap”
All in, this took me about 1 hour to code, much much faster than without ChatGPT. Of course, there’s some areas of improvement…
- Bug: The Webapp doesn’t really work. I would need to expose the Sheet data through a webhook, which is possible, but I didn’t bother with this today :)
- Feature Idea: Send me a daily summary of all your unread emails (You could ask AI for sentiment analysis but just the subject lines is probably enough)
- Feature Idea: Create another filter for “Very important” emails that should be texted to you and/or treated differently.
✉️ Final Thoughts
Email isn’t going away. It’s a pure numbers game for marketers these days, but with a little automation, I’ve made email less of a burden.
🌕 The importance of Learning Things The Hard Way: If you want to learn more about Google Apps Script and automation, there’s a lot of resources online. I definitely recommend spending time to learn low code tools like GAS work and all of their capabilities, because it’s a lifelong skill that is enjoyable and gives you super powers.
Helpful Links / Contact
If you found this useful, follow me here. I will share more automation ideas on Medium and Substack when I have time.
If you want to see the full working code, check my github link below: https://github.com/danphamx/Apps-Script-Gmail-Automation-Nov-2025
I mostly wrote this for general education for friends and tech workers, but if you would like to discuss a project, send me a brief message on LinkedIn.
메타데이터
- post_id
- adb87f77c698
- slug
- i-built-a-free-gmail-automation-with-google-apps-script-chatgpt-adb87f77c698
- url
- https://medium.com/create-digital-gardens-with-ai/i-built-a-free-gmail-automation-with-google-apps-script-chatgpt-adb87f77c698
- canonical_url
- https://medium.com/create-digital-gardens-with-ai/i-built-a-free-gmail-automation-with-google-apps-script-chatgpt-adb87f77c698
- author_url
- https://medium.com/@danphamx
- status
- ok
- fetched_at
- 2026-08-02 11:52:24