Mail Service

A simple email forwarding service built with Next.js that sends emails via Gmail API. Supports plain text, HTML templates, and automatic object formatting.

View Full Documentation on GitHub

Features

📧

Gmail API Integration

Send emails via Gmail API

🎨

Multiple Formats

Support for plain text, HTML, and object-based emails

🔄

Auto Formatting

Automatic field name formatting (e.g., full_name → "Full Name")

📝

Templates

Template support with data substitution

🔐

OAuth 2.0

Authentication with refresh tokens

🔒

API Key Auth

Secure access with API key authentication

Rate Limiting

Prevents abuse with configurable rate limits

🌐

CORS Enabled

Cross-origin requests support

API Endpoint

POST/api/sendmail

Sends an email via Gmail API

Request Headers:

Content-Type: application/json
X-API-Key: your-api-key

Content Types:

Plain Text

{
  "text": "Hello"
}

HTML

{
  "html": "<h1>Hello</h1>"
}

Fields Object

{
  "fields": {
    "name": "John"
  }
}

Example Request Body:

{
  "to": "recipient@example.com",
  "subject": "Hello",
  "text": "This is a test email."
}

Security

🔒 API Key Protection

Optional API key authentication. If API_KEY is set in environment variables, all requests must include a valid API key.

Rate Limiting

With API key: 10 requests/minute. Without API key: 5 requests/minute. Rate limit info is included in response headers.

Quick Start

Full guide

1. Install dependencies

pnpm install

2. Set up environment variables

GMAIL_API_KEY=your-client-id
GMAIL_SECRET=your-client-secret
GMAIL_REFRESH_TOKEN=your-refresh-token
GMAIL_SENDER_EMAIL=your-email@gmail.com
API_KEY=your-api-key

3. Get refresh token

GET http://localhost:3000/api/auth/google

For detailed setup instructions, examples, and troubleshooting, see the full documentation on GitHub.