Skip to content
Harshit-Maurya838Public

About

Lightweight, open-source, self-hosted email-sending API for Vercel, Netlify, Docker, and Node.js using Nodemailer. Send transactional emails with a simple POST /mail request.

Topics

Resources

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

12 Commits

Folders and files

Repository files navigation

MailSync

License: MIT Node.js GitHub stars Deploy with Vercel Deploy to Netlify

⭐ Support the Project: If you like or use MailSync, please consider giving the repo a star on GitHub β€” it helps keep the project active and maintained!

MailSync is a lightweight, open-source, self-hosted email-sending API built with Node.js, Express, and Nodemailer. It allows anyone to deploy a private, serverless email API to Vercel, Netlify, Docker, or any VPS in less than 60 seconds.

Stop paying for expensive third-party email delivery services for simple contact forms, transactional notifications, verification codes, or alerts.


✨ Features

  • Single Clean Endpoint: Send transactional emails with a simple POST /mail (or POST /api/mail).
  • Zero Config Serverless: Pre-configured for seamless 1-click deployments on Vercel and Netlify.
  • Works with Gmail & Any Provider: Built-in support for Gmail App Passwords, SendGrid, Mailgun, or custom SMTP servers.
  • Built-in HTML Email Formatting: Raw text messages are automatically wrapped into clean, modern, mobile-responsive HTML templates. Custom HTML is also fully supported.
  • Optional API Key Security: Protect your endpoint with an x-access-key header, or leave it open for public contact forms.
  • Interactive Web Dashboard: Built-in browser playground to test your API, inspect live logs, and generate client code snippets in cURL, JavaScript, and Python.
  • Docker Ready: Includes production Dockerfile and docker-compose.yml.

πŸš€ 1-Click Deployment

Deploy to Vercel

Deploy with Vercel

  1. Click the button above to import this repository.
  2. Set your environment variables in Vercel:
    • EMAIL_USER: Your Gmail address (e.g. yourname@gmail.com)
    • EMAIL_PASSWORD: Your 16-character Google App Password
    • ACCESS_KEY: (Optional) Secret token to protect your /mail endpoint
  3. Click Deploy. Your API is live!

Deploy to Netlify

Deploy to Netlify

Netlify is supported via the included netlify.toml and serverless function adapter. Add the environment variables in your Netlify Site Settings.


πŸ’» Local Development Setup

  1. Clone the repository:

    git clone https://github.com/Harshit-Maurya838/MailSync.git
    cd MailSync
  2. Install dependencies:

    npm install
  3. Configure environment variables:

    cp .env.example .env

    Edit .env and fill in your email credentials:

    EMAIL_USER=your-email@gmail.com
    EMAIL_PASSWORD=your-16-character-app-password
    ACCESS_KEY=my-super-secret-key
    PORT=5000

    Note on Gmail: You need a Google App Password, not your normal account password. Generate one at Google Account App Passwords.

  4. Start the server:

    npm run dev

    Open http://localhost:5000 in your browser to view the interactive dashboard.


πŸ“‘ API Reference

Send Email

POST /mail

(Also available at POST /api/mail)

Headers

Header Value Description
Content-Type application/json Required
x-access-key YOUR_ACCESS_KEY Required only if ACCESS_KEY is configured
Authorization Bearer YOUR_ACCESS_KEY Alternative to x-access-key

Request Body

{
  "email": "recipient@example.com",
  "name": "Alex Rivers",
  "subject": "Welcome to MailSync!",
  "message": "Hello! Your account has been created successfully."
}
Field Type Required Description
email or to string Yes Target recipient email address
message string Yes* Email body text (auto-wrapped in clean HTML layout with watermark)
html string No* Custom HTML body if you want full layout control
subject string No Email subject line (default: "New Notification from MailSync")
name string No Personalizes the greeting (e.g., "Hello Alex,")
fromName string No Custom sender/from name (e.g., "Acme Team"). Overrides FROM_NAME.
from string No Full custom sender header (e.g. "Acme" <support@domain.com>)

* Either message or html must be provided. πŸ›‘οΈ Note: All emails include an open-source watermark badge ("⚑ Powered by MailSync β€’ Open Source Project") in the footer.

Response

{
  "success": true,
  "message": "Email sent successfully",
  "messageId": "<b6589fc6-8e12-7dc2-359a-20a52cfa4323@gmail.com>",
  "recipient": "recipient@example.com"
}

Diagnostic Endpoints

  • GET /health: Healthcheck endpoint returning system status and timestamp.
  • GET /server-info: Real-time server uptime, mail dispatch counts, and auth state.
  • GET /api/verify: Validates the Nodemailer connection to your mail provider without sending an email.
  • GET /logs: Returns recent server activity logs. Requires the access key when ACCESS_KEY is set; recipient addresses are masked.

πŸ’‘ Code Examples

cURL

curl -X POST "https://your-mailsync.vercel.app/mail" \
  -H "Content-Type: application/json" \
  -H "x-access-key: your-secret-key" \
  -d '{
    "email": "user@example.com",
    "name": "Alex",
    "subject": "Order Confirmation",
    "message": "Thank you for your purchase!"
  }'

JavaScript (Fetch)

const response = await fetch("https://your-mailsync.vercel.app/mail", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-access-key": "your-secret-key"
  },
  body: JSON.stringify({
    email: "user@example.com",
    name: "Alex",
    subject: "Welcome!",
    message: "Thank you for joining our platform."
  })
});

const data = await response.json();
console.log(data);

Python

import requests

url = "https://your-mailsync.vercel.app/mail"
headers = {
    "Content-Type": "application/json",
    "x-access-key": "your-secret-key"
}
payload = {
    "email": "user@example.com",
    "name": "Alex",
    "subject": "Security Code",
    "message": "Your verification code is 492041."
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

πŸ€– AI Agent Integration & Guided Prompt

Integrate your hosted MailSync instance into any application (Next.js, Node.js, Python, React, Go) in seconds using an AI coding assistant (Cursor, Antigravity, Claude Code, Copilot, or Windsurf).

πŸ“‹ 1-Click Agent Prompt

Copy and paste this prompt directly into your AI assistant:

Please implement transactional email sending in this application using our hosted MailSync API instance.

### MailSync Instance Details:
- Base API URL: https://your-mailsync.vercel.app (or https://mailsync-sigma.vercel.app)
- Endpoint: POST /mail (or POST /api/mail)
- Headers:
  - Content-Type: application/json
  - x-access-key: [YOUR_ACCESS_KEY or none if public]

### Request Body Schema (JSON):
{
  "email": "user@example.com",
  "name": "Alex",
  "subject": "Order Confirmation",
  "message": "Thank you for your purchase!"
}

### Steps for the Agent:
1. Environment Setup: Add `MAILSYNC_API_URL` (and optional `MAILSYNC_ACCESS_KEY`) to `.env`.
2. Client Service: Create a clean email utility module (e.g., `lib/mailsync.ts` or `services/email.ts`) that POSTs to `/mail`.
3. Wire Feature: Connect the utility to our user-facing triggers (contact form, verification, or notification).
4. Verify: Test against `GET /health` and dispatch a test email.

⚑ Antigravity Agent Skill

If using the Antigravity IDE or agy CLI, copy the included skill from .agents/skills/mailsync-integration/ to your application's .agents/skills/ directory. The agent will automatically detect and apply all best practices.

See INTEGRATION_PROMPT.md for full documentation and framework examples.


βš™οΈ Environment Variables

Variable Default Description
EMAIL_USER None Email address used for authentication (e.g. Gmail)
EMAIL_PASSWORD None Email password or Google App Password
FROM_NAME "MailSync" Default sender/from name (e.g. "MyBrand", "Acme Support")
EMAIL_SERVICE gmail Nodemailer service provider (gmail, sendgrid, mailgun, etc.)
EMAIL_FROM "${FROM_NAME}" <EMAIL_USER> Full custom sender header (overrides FROM_NAME)
ACCESS_KEY None Secret key required to send emails. If empty, the endpoint is public.
PORT 5000 Port for the standalone Node.js server

🐳 Docker Deployment

Run with Docker:

docker build -t mailsync .
docker run -p 5000:5000 \
  -e EMAIL_USER=your-email@gmail.com \
  -e EMAIL_PASSWORD=your-app-password \
  -e ACCESS_KEY=your-access-key \
  mailsync

Or with Docker Compose:

docker-compose up -d

🀝 Contributing

Contributions are welcome and greatly appreciated! Please review our Contributing Guide to get started with local development, architecture overview, commit conventions, and pull requests.


πŸ“„ License

This project is licensed under the MIT License. Feel free to fork, customize, and use it in your personal or commercial projects.

About

Lightweight, open-source, self-hosted email-sending API for Vercel, Netlify, Docker, and Node.js using Nodemailer. Send transactional emails with a simple POST /mail request.

Topics

Resources

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Contributors

Languages