Skip to content
codextechorgPublic

About

Open source, self-hostable mass email campaigns through your own Mailgun account: CSV/Excel lists, drag-and-drop designer, per-recipient attachments.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Postgun

Open source (AGPL-3.0) mass email campaigns through your own Mailgun account. Self-host it for free with no limits, or use the hosted version at postgun.codextech.org (free plan, Pro plan).

Multi-user platform for designing and sending mass email campaigns through each user's own Mailgun account.

Features

  • Accounts with email + password (bcrypt, signed session cookie)
  • Mailgun connections: API key, domain, US/EU region. Keys are verified on save and encrypted with AES-256-GCM
  • Lists from CSV or XLSX: pick the email column, optional "first N rows" limit, Windows-1252 CSVs handled. Every column becomes a merge tag ({{name}}, {{order}}, …)
  • Email designer: Unlayer drag-and-drop, or raw HTML (Monaco) with live preview
  • Shared attachments (same file for everyone)
  • Per-recipient attachments: upload files or a ZIP, set a pattern like certificate {{order}}.jpg, optionally rename to {{name}}.jpg
  • Unsubscribe link in every email (auto-added if missing), RFC 8058 one-click List-Unsubscribe header
  • Suppressions: unsubscribes, manual entries, and Mailgun bounces/complaints/unsubscribes (imported before every send)
  • Sender address rotation (optional, per campaign) to keep spam rates down on large sends: every 100 recipients get a newly generated address like k3f9x2qa@yourdomain, while the sender name stays the same
  • Background worker with DB locks: pause, resume, cancel, retry failed, live progress, per-recipient log

How sending works

Mode When How
Batch No per-recipient files 500 recipients per Mailgun call using recipient-variables (100 with sender address rotation, one address per call)
One by one Per-recipient files set 5 parallel requests, each with its own attachment

Failed requests retry 3 times (longer back-off on HTTP 429). A 401/403 from Mailgun stops the campaign with an error. Recipients are snapshotted when sending starts, so a crash or redeploy resumes where it left off.

Local development

Requires Node 24+ (26 LTS recommended) and MariaDB (or MySQL 8).

cp .env.example .env      # fill in DATABASE_URL, SESSION_SECRET, ENCRYPTION_KEY
npm install
npm run db:migrate        # creates the database and tables
npm run dev               # web app on http://localhost:3000
npm run worker            # in a second terminal: sends campaigns

After changing src/db/schema.ts, run npm run db:generate and commit the new file in drizzle/.

Deploying on Coolify

  1. Create a MariaDB resource in Coolify (or reuse one) and copy its internal connection URL.
  2. New resource → Docker Compose → this repository. Coolify reads docker-compose.yml.
  3. Set DATABASE_URL to the MariaDB URL, ending in the database name (e.g. mysql://user:pass@<mariadb-container>:3306/postgun).
  4. Enable "Connect to Predefined Network" on the compose resource so app and worker can reach the database container.
  5. Set a domain on the app service (port 3000). APP_URL and the secrets are generated by Coolify.
  6. Deploy. The app applies migrations on start; the worker service sends campaigns. Both share the storage volume.

ENCRYPTION_KEY must never change after users connect Mailgun, or their stored keys can't be decrypted.

Environment

Variable Purpose
DATABASE_URL mysql://user:pass@host:3306/postgun (URL-encode special characters, @ → %40)
SESSION_SECRET Signs sessions and unsubscribe links
ENCRYPTION_KEY Encrypts Mailgun API keys (random string, 32+ characters)
APP_URL Public URL, used in unsubscribe links
UPLOAD_DIR Attachment storage, shared by app and worker
WORKER_CONCURRENCY Campaigns sent in parallel per worker (default 3)
MAILGUN_API_BASE Testing only: send all Mailgun calls to a mock server
SOURCE_URL Link to the source shown in the footer (AGPL-3.0 section 13). Point it at your fork if you modify Postgun
CLIENT_IP_HEADER Header your reverse proxy sets to the real client IP, used for sign-in rate limits. Default x-real-ip (Traefik, nginx); use cf-connecting-ip behind Cloudflare
PAYPAL_*, LIFETIME_DEAL_* Optional hosted billing, see below. Leave unset when self-hosting

Self-hosting

Everything above is all you need. With no PAYPAL_CLIENT_ID set, billing is off: there are no email limits, every feature is unlocked, and the Billing page and pricing page don't exist.

The public pages under src/app/(site) (terms, privacy, refunds, comparisons) are written for the hosted service run by Codex Tech. Replace them with your own text before opening your instance to other people.

Admin

Admin is a database role, not an email allowlist (signup doesn't verify email, so an allowlist could be claimed by whoever registers first). Register in the app, then grant yourself access:

npm run admin:grant -- you@example.com
npm run admin:revoke -- you@example.com

Admins get an Admin section: platform overview (users, usage, revenue), a searchable user list with plan and usage, a user page to change plans, set a custom monthly limit, suspend or unsuspend, and a feed of every campaign across users. The admin tools show metadata only, never Mailgun keys, recipient lists or email bodies. Every admin action is logged to admin_actions.

Optional: hosted billing with PayPal

Used by postgun.codextech.org. Free plan: 2,000 emails a month. Pro: 50,000 emails a month plus per-recipient attachments and sender address rotation, monthly (PayPal Subscriptions) or a limited lifetime deal (PayPal Orders). Limits are counted in a ledger (user_usage) that the worker reserves from before each send, so parallel campaigns can't overshoot. Buyers pay through PayPal's buttons on the Billing page (PayPal Web SDK v6) without leaving the app; if the PayPal script is blocked, the page falls back to a redirect to PayPal.

  1. Create a REST app at developer.paypal.com (sandbox first). Set PAYPAL_ENV, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET.
  2. npm run paypal:setup creates the Pro product and monthly plan and prints PAYPAL_PLAN_PRO.
  3. Add a webhook to the app pointing at <APP_URL>/api/billing/paypal/webhook with the events BILLING.SUBSCRIPTION.*, PAYMENT.SALE.COMPLETED, PAYMENT.CAPTURE.COMPLETED, PAYMENT.CAPTURE.REFUNDED, and set PAYPAL_WEBHOOK_ID.
  4. Optional lifetime deal: LIFETIME_DEAL_ENABLED=true, LIFETIME_DEAL_LIMIT=100.
  5. When launching billing on an instance that already has users, order matters: deploy and migrate with the PayPal variables unset, run npm run billing:grandfather -- 60 once (gives every existing user Pro for 60 days so running campaigns and quotas aren't cut off), and only then set the PayPal variables and redeploy. Grandfathered users can still subscribe or buy lifetime at any time; a paid plan replaces the grace grant.

The app and the worker need the same billing variables. PayPal is not a merchant of record: VAT and sales tax are your responsibility.

Changelog

See CHANGELOG.md for release notes. The same notes are on the site at /changelog.

License

AGPL-3.0. If you run a modified version as a network service, you must offer your users the source of your changes.

About

Open source, self-hostable mass email campaigns through your own Mailgun account: CSV/Excel lists, drag-and-drop designer, per-recipient attachments.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages