Case study · Full-stack AI app

Smart Mail, an AI Email Assistant

Smart Mail reads your unread Gmail, drafts a reply with Google Gemini, lets you edit it, and sends it back into the same thread. A React + TypeScript front end talks to a Flask API, and Supabase handles accounts.

30latest unread Primary emails per fetch
10prompt rules that keep drafts specific
4API endpoints: auth check, unread, draft, send
4Supabase tables: users, templates, history, settings
01Problem

Routine email eats time, and generic AI drafts often aren't much better. They come back vague, unsigned, or full of placeholders like [briefly mention reason] that you have to fix by hand. The goal was a draft you could send after a quick read, with the person still in control of what goes out.

02Approach
ConnectGmail OAuthRead, compose and send scopes, with token refresh
FetchUnread inboxLatest 30 in Primary, with subject, sender and date
UnderstandDecode bodyMIME text/plain + sender's name
DraftGemini promptStructure rules + your own instructions
CleanRegex passStrips leftover bracketed placeholders
SendThreaded replyAfter you review and edit

a few of the prompt rules (abridged) ↓

# generate_reply() → Gemini 1.5 Flash
1. Begin with: "Dear {sender_name},"
2. Address all points from the original message.
4. DO NOT include bracketed text like [suggest timeframe].
7. Use concrete timeframes like "48 hours".
8. End with: "Best regards,\n{user_name}"

Front end (React + TypeScript)

Supabase sign-up/sign-in, an inbox dashboard, email detail and reply form, a chat-style assistant widget, plus profile and settings pages.

Back end (Flask)

Blueprints for /check-auth, /unread, /generate-reply and /send-reply, all wrapping the Gmail API and Gemini.

03Details

Prompt rules plus post-processing

The prompt sets the structure (greeting with the sender's name, one paragraph per point, sign-off with your name), and a regex pass removes any bracketed placeholders the model still produces.

Replies stay in the thread

Sent replies carry the In-Reply-To and References headers plus Gmail's threadId, so they appear in the original conversation instead of as new emails.

Your instructions shape the draft

Optional extra context ("decline politely", "propose Thursday") is added to the prompt before generation.

Human in the loop

Nothing is sent automatically. Every draft is shown for review and editing first, and the command-line version lets you choose reply-to-sender, reply-all or custom recipients.