Back to .md Directory

Submail System

Describes a self-hosted email alias system for Discord communities with SMTP engine, alias management, and audit logging.

May 2, 2026
0 downloads
0 views
ai
View source

What this file does

Describes a self-hosted email alias system for Discord communities with SMTP engine, alias management, and audit logging.

When to use it

  • You want to offer Discord members disposable email aliases
  • You need a self-hosted email forwarding service with Discord authentication
  • You are building a community tool that requires email alias management
  • You want to deploy a secure email gateway with spam filtering

Assumes this stack

Next.js 14TypeScript 5.0Prisma 5.0Node.jsDocker

<div align="center">Submail System</div>

<div align="center">

Next.js TypeScript Prisma License

A Secure, Self-Hosted Email Alias System for Discord Communities.

Features β€’ Prerequisites β€’ Quick Start β€’ Environment

</div>

Features

  • πŸ” Discord Gate: Restrict access to your guild members.
  • πŸ›‘οΈ Advanced Security: CSP, HSTS, Rate Limiting, and PII Masking by default.
  • πŸ“§ SMTP Engine: Built-in Node.js SMTP server with spam filtering.
  • πŸ“ Alias Management: Create, Pause, and Delete aliases instantly.
  • πŸ“Š Audit Logs: Track every forwarded email and blocked attempt.

Prerequisites

Before you begin, ensure you have:

  • Node.js: v20 or higher (v22 Recommended)
  • Docker: For easy deployment (Optional)
  • Discord Application: Create one at Discord Developers.

Quick Start

Get up and running locally in 3 steps.

1. Clone & Install

git clone https://github.com/minseo0388/submail.git
cd submail
npm install

2. Configure Environment

Copy the example file and fill in your Discord keys.

cp .env.example .env

(See Environment Setup for details)

3. Run

Start the development server (Web + Bot).

npx prisma db push
npm run dev

Open http://localhost:3000 to verify.


Environment Setup

The .env file is the heart of your security configuration.

πŸ”‘ Identity & Database

VariableDescriptionExample
DATABASE_URLSQLite or PostgreSQL URLfile:./dev.db
AUTH_SECRETSecret for session encryptionopenssl rand -base64 32
NEXTAUTH_URLURL of your dashboardhttp://localhost:3000

πŸ€– Discord Configuration

VariableDescription
DISCORD_CLIENT_IDOAuth2 Client ID
DISCORD_CLIENT_SECRETOAuth2 Client Secret
DISCORD_GUILD_ID(Optional) Restrict login to this Server ID

⚑ Rate Limiting (Upstash)

VariableDescription
UPSTASH_REDIS_REST_URLRedis URL for Rate Limiting
UPSTASH_REDIS_REST_TOKENRedis Access Token

πŸ“¨ Mail Server

VariableDescriptionDefault
SMTP_PORTPort for incoming mail25
SMTP_DOMAINDomain for aliasesexample.com

πŸš€ Deployment Guide

Vercel (Web Dashboard)

  1. Push your code to GitHub.
  2. Import the project in Vercel.
  3. Environment Variables: Add all variables from .env to Vercel Settings.
  4. Build Command: npx prisma generate && next build
    • Note: The SMTP server (apps/bot) cannot run on Vercel. You need a separate VPS or generic host (Render/Railway/EC2) for the Bot.

Database Migration

When deploying to production:

# Apply migrations to prod DB
npx prisma migrate deploy


πŸ“‘ Deliverability & DNS

To ensure your emails land in the Inbox (not Spam), you must configure these DNS records.

1. Reverse DNS (PTR)

Action: Go to your VPS Provider (AWS, DigitalOcean, etc.) settings.

  • Value: mail.yourdomain.com (Must match your SMTP hostname)

2. SPF (Sender Policy Framework)

Record Type: TXT

  • Host: @
  • Value: v=spf1 mx a:mail.yourdomain.com -all

3. DKIM (DomainKeys Identified Mail)

Record Type: TXT

  • Host: default._domainkey (or your selector)
  • Value: v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY_HERE

    Note: Generate this keypair using openssl or an online tool. Put the private key on your server and path in .env.

4. DMARC

Record Type: TXT

  • Host: _dmarc
  • Value: v=DMARC1; p=quarantine; rua=mailto:admin@yourdomain.com

Troubleshooting

<details> <summary><strong>SMTP Port Permission Denied?</strong></summary> Port 25 requires root privileges. On Linux, grant permission to Node:
sudo setcap 'cap_net_bind_service=+ep' $(which node)
</details> <details> <summary><strong>Redis Connection Error?</strong></summary> If you see "Redis Error (Fail-open)", check your Upstash credentials. The system will continue to work but without rate limiting. </details>
<div align="center"> Made with ❀️ by Choi Minseo </div>

What's inside

7 sections: features, prerequisites, quick start, environment setup, deployment guide, DNS deliverability, troubleshooting

Change this for your project

  • Replace minseo0388/submail with your own repository name
  • Replace example.com with your actual domain for SMTP aliases
  • Replace mail.yourdomain.com with your SMTP hostname in DNS records

Where it goes

Save as AGENTS.md in your repository root. Read by Codex, Cursor and other agents that follow the AGENTS.md convention.

Worth borrowing

  • Using Discord OAuth2 as the sole authentication gate for a self-hosted service
  • Combining a web dashboard with a separate SMTP bot process for deployment flexibility

Related Documents