If you run a service business, your inbox is where jobs either get captured or quietly disappear. You're on a roof or under a sink, and while you're working, a new lead lands next to a parts inquiry, an overdue invoice question, and three things that aren't your problem. By the time you look at your phone, it's a wall of unread messages and you're already tired.
This weekend you can build a lightweight triage system that runs inside Gmail itself — no new platform, no monthly subscription, no server. It reads your unread emails each morning, labels them by type, and drafts a reply for the ones that matter. The tools are free: Google Apps Script (free, built into every Google account) and the Gemini API (free tier covers a small business comfortably).
What you'll build
A time-triggered script that runs every morning at 7 AM, scans your last 20 unread emails, and for each one:
- Classifies the email into one of your defined buckets (new lead, schedule change, invoice question, supplier, spam/ignore)
- Applies a Gmail label so you can see at a glance what's waiting
- For "new lead" and "schedule change" messages, creates a draft reply in your voice — ready to review and send in 10 seconds
You stay in control: nothing sends automatically. The AI does the reading and drafting; you do the approving. That's the right division of labor.
What you need (setup takes about 30 minutes)
- A Gmail account (personal or Google Workspace — both work)
- A free Gemini API key from Google AI Studio — no billing information required for the free tier
- No downloads, no installs, nothing else
The Gemini 2.5 Flash model is the right choice here: fast, accurate, and the free tier allows roughly 1,500 requests per day — far more than a small business inbox needs.
Step 1: Get your free API key
Go to aistudio.google.com, sign in with your Google account, and click Get API key. Copy it somewhere safe. That's it — no billing setup required to start.
Step 2: Open Apps Script and write the bot
In Gmail, click the Apps Launcher (the nine-dot grid), search for Apps Script, and open it. You'll land in an editor with an empty myFunction(). Replace everything with the following:
const GEMINI_KEY = 'YOUR_API_KEY_HERE';
const GEMINI_URL = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=' + GEMINI_KEY;
const CATEGORIES = ['new-lead', 'schedule-change', 'invoice-question', 'supplier', 'ignore'];
function triageInbox() {
const threads = GmailApp.getInboxThreads(0, 20);
for (const thread of threads) {
const msg = thread.getMessages()[thread.getMessageCount() - 1];
if (!msg.isUnread()) continue;
const subject = msg.getSubject();
const body = msg.getPlainBody().substring(0, 1500); // cap context
const from = msg.getFrom();
// --- Classify ---
const classPrompt = `You are a triage assistant for a small service business.
Classify this email into exactly one of: ${CATEGORIES.join(', ')}.
Return only the category name, nothing else.
FROM: ${from}
SUBJECT: ${subject}
BODY: ${body}`;
const category = callGemini(classPrompt).trim().toLowerCase();
// Apply label
let label = GmailApp.getUserLabelByName('triage/' + category);
if (!label) label = GmailApp.createLabel('triage/' + category);
label.addToThread(thread);
// --- Draft reply for high-priority types ---
if (category === 'new-lead' || category === 'schedule-change') {
const draftPrompt = `You are a friendly, professional assistant for a small service business.
Write a short, warm reply (under 80 words) to this email.
Acknowledge what they need, confirm you'll follow up personally, and give one specific next step.
Do not add a subject line. Do not use placeholders like [Your Name].
FROM: ${from}
SUBJECT: ${subject}
BODY: ${body}`;
const draftBody = callGemini(draftPrompt);
GmailApp.createDraft(
msg.getReplyTo() || from,
'Re: ' + subject,
draftBody
);
}
}
}
function callGemini(prompt) {
const payload = JSON.stringify({
contents: [{ parts: [{ text: prompt }] }]
});
const options = {
method: 'post',
contentType: 'application/json',
payload: payload,
muteHttpExceptions: true
};
const response = UrlFetchApp.fetch(GEMINI_URL, options);
const json = JSON.parse(response.getContentText());
return json.candidates[0].content.parts[0].text;
}
Replace YOUR_API_KEY_HERE with the key you copied from AI Studio. Save the file (Ctrl+S or Cmd+S) and give the project a name like Gmail Triage Bot.
Run triageInbox() once manually by clicking the Run button. The first time, Google will ask you to authorize the script to access your Gmail — click through and approve. This is your script, running under your own account, calling only your own mailbox.
Step 3: Set the daily trigger
In the left sidebar, click the clock icon (Triggers). Add a trigger: function triageInbox, event source Time-driven, type Day timer, time 7 AM – 8 AM. Save it. From now on, every morning before you pick up your first coffee, your inbox has already been sorted and your first draft replies are waiting.
Making it yours
The two prompts are where the real customization lives. A few things worth adjusting before you go live:
- Your category list. Replace the defaults with what actually matters to your business:
'water-heater-emergency','warranty-claim','repeat-customer','subcontractor'. More specific buckets produce more accurate labels. - Your business voice. The draft prompt is where you shape the tone. Add a line like: "We are a plumbing company in the Comox Valley. We're friendly but direct. Never make commitments about pricing or availability in the reply." This keeps AI-drafted messages on-brand and safe.
- Which emails get drafts. Right now it drafts for
new-leadandschedule-change. Addinvoice-questionif you want draft replies for those too, or removeschedule-changeif you'd rather handle those personally. - The email cap. The script processes the top 20 unread threads. Change that number if your inbox volume is higher or lower.
Honest limits
The script reads only the most recent message in each thread, not the full conversation history — so context-heavy back-and-forths may get classified less accurately. And like any AI, it will occasionally miscategorize a message; the labels are a starting point, not gospel. Review the drafts before you send them — especially early on, while you're tuning the prompts. Keep a human eye on anything that involves pricing, scheduling commitments, or warranty disputes.
What to do this weekend
- Get your free Gemini API key from AI Studio — takes two minutes.
- Paste the script into script.google.com and replace the API key placeholder.
- Adjust the category list and the draft prompt to match your actual business.
- Run it once manually on a batch of real emails and see how accurate the classification is. Tweak the prompt if it's missing the mark.
- Set the daily trigger and let it run Monday morning for the first live test.
The payoff is concrete: instead of opening your inbox to a wall of undifferentiated messages, you open it to a sorted, colour-coded triage with draft replies queued for the things that matter. The AI does the first pass; you make the calls. That split is what makes it actually useful — and safe enough to trust on a Monday morning.
