A production-ready AI email agent built with Next.js App Router, OpenAI GPT-4o, and Gmail API.
- AI Draft Generation — Describe your topic, GPT-4o writes the email
- Draft Editing — Review and edit before sending
- Gmail Integration — Sends via OAuth2 through your Gmail account
- Premium UI — Dark mode, glassmorphism, Framer Motion animations
# Install dependencies
npm install
# Copy env template and fill in your keys
cp .env.example .env.local
# Start dev server
npm run devOpen http://localhost:3000.
Create a .env.local file:
OPENAI_API_KEY=sk-...
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REFRESH_TOKEN=your-refresh-token
- Go to Google Cloud Console
- Create a new project (or select existing)
- Enable the Gmail API
- Go to APIs & Services → Credentials
- Create an OAuth 2.0 Client ID (Web application)
- Add
https://developers.google.com/oauthplaygroundas an authorized redirect URI
- Add
- Note your Client ID and Client Secret
- Go to OAuth 2.0 Playground
- Click the gear icon → Check "Use your own OAuth credentials"
- Enter your Client ID and Secret
- In Step 1, select
https://mail.google.com/ - Authorize and exchange for tokens
- Copy the Refresh Token
npm i -g vercel
vercelAdd your environment variables in Vercel dashboard → Settings → Environment Variables.
| Layer | Technology |
|---|---|
| Framework | Next.js 15 App Router |
| AI | OpenAI GPT-4o |
| Gmail API (OAuth2) | |
| Styling | Tailwind CSS v4 |
| Animation | Framer Motion |
| Language | TypeScript |
src/
├── app/
│ ├── api/
│ │ ├── generate-draft/
│ │ │ └── route.ts # OpenAI draft generation
│ │ └── send-email/
│ │ └── route.ts # Gmail API send
│ ├── globals.css # Design system
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main page (state machine)
└── components/
├── ComposeForm.tsx # Email compose form
├── DraftPreview.tsx # Editable draft preview
├── ErrorDisplay.tsx # Error state
└── SuccessView.tsx # Success animation