mailcheap README

项目的 README,来自 github.com/marclou/mailcheap。合并为一个 markdown 文件:README.md。

MailCheap

MailCheap

Newsletters where you pay for the emails you send, not for dormant subscribers.
A fraction of the price of beehiiv and the like.

Website · API docs · Sign up for MailCheap Cloud

License: AGPL-3.0 Node.js 22 or later MCP server

MailCheap's overview: emails sent, delivery, open, click, bounce and complaint rates, and subscribers over the last 30 days

MailCheap is a newsletter app: write an issue, send it to your list, publish it on the web, from the dashboard or from your AI agent. This repository is the whole app. Self-host it with your own Amazon SES or PostShiba account, or use MailCheap Cloud, which runs this same code.

Features

Write, review, send The newsletter's website
The campaign editor's Write step: the subject, preview text and body of a draft, with the Write, Review and Send steps at the top A newsletter's website: its signup form, a featured issue and the latest issues

All names and addresses in the screenshots are made up.

MailCheap Cloud or self-hosted

MailCheap Cloud Self-hosted
Price From $19 a month for 20,000 emails Free, plus what your provider charges per email: $0.10 to $0.16 per 1,000 on Amazon SES
Sending Set up for you, from hello@<slug>.mailcheap.ai or your domain Your Amazon SES or PostShiba account, from your domain
Website <slug>.mailcheap.ai /archive/<slug> on your server's domain
Who signs in Anyone who signs up The emails you allow
Limits Emails a month and active subscribers, by plan None
Setup A few minutes About an hour, most of it waiting for DNS and production access
Support A chat in the dashboard None: issues are off

MailCheap Cloud is this repository with MAILCHEAP_CLOUD=true, which adds open sign-up, plans and Stripe billing. Only active subscribers count toward a plan, not the ones list cleanup marked dormant. Its marketing site (the landing, pricing and legal pages) isn't part of the open source. Every change to the app ships to both.

With your own sending account, you pay your provider for the emails you send: 10,000 readers and 4 issues a month is 40,000 emails, about $4 to $6 on Amazon SES.

Self-hosting

Deploy with Vercel

Plan for about an hour, most of it waiting for DNS and for your provider to approve production sending. Self-hosting comes without support: issues are off and setup questions go unanswered.

What you need

Service For Cost
MongoDB Contacts, campaigns, stats Free tier works
Amazon SES or PostShiba Sending SES: $0.10 to $0.16 per 1,000 emails, depending on its pricing plan. PostShiba: a fixed price per cluster, invite only for now
Upstash QStash Background sending and scheduling Free tier to start, then pay per message. One message sends 50 emails
Vercel or any Node.js 22+ host Hosting Free tier works
Resend (optional) Sign-in codes and alerts. Without it, they go through SES or PostShiba Free plan works
Upstash Redis (optional) Rate limits shared by every server instance Free tier
Amazon S3 with CloudFront, or Vercel Blob (optional) Image uploads in the editor, the newsletter settings and the API S3 and CloudFront: pay per use. Blob: free tier

Without Redis, MailCheap counts the same rate limits in each server instance's memory. That still stops a script hammering a form, but on serverless hosts the limits aren't shared between instances and reset on each deploy. Add Redis before you put a signup form on a busy site. Without S3 or Blob, image uploads are off; HTML and Markdown campaigns can still use images hosted anywhere.

Environment variables

Variable What it does
MONGODB_URI MongoDB connection string with a database name
BETTER_AUTH_SECRET Signs sessions and every link in sent emails. 32+ random characters (openssl rand -base64 48), or the server refuses to start. Rotating it signs everyone out and breaks links in emails already sent
SUPPRESSION_HASH_KEY Keys the hashes of the never-email list every account shares. 32+ random characters of its own, never BETTER_AUTH_SECRET, or the server refuses to start, after an upgrade too. Changing it empties the list
ADMIN_EMAILS Comma-separated emails that can sign in and open /admin
ALLOWED_EMAILS Who else can sign in: addresses and @domain entries, comma-separated
EMAIL_FROM From address of sign-in codes and alerts, on a domain your Resend account or email provider verified
APP_URL Public URL of the app, for email links and sign-in. On Vercel it defaults to the production domain
RESEND_API_KEY Optional: sign-in codes and alerts through Resend. Without it, they go through the email provider
SENDING_ENABLED Nothing goes to readers unless it's true. Sign-in codes and alerts don't wait for it
SES_* or POSTSHIBA_* The email provider, in step 4
QSTASH_* Background sending and scheduling, in step 5

.env.example lists every variable with what it does, the optional ones included: Google sign-in and Postmaster Tools, image uploads, Redis, Telegram alerts, the shared domain, and MailCheap Cloud's own.

1. Database

  1. Create a free cluster on MongoDB Atlas.
  2. Database Access: add a user with a password and the "Read and write to any database" role.
  3. Network Access: allow 0.0.0.0/0. Vercel doesn't have fixed IP addresses.
  4. Connect > Drivers: copy the connection string and add a database name before the ?, like ...mongodb.net/mailcheap?retryWrites=true. That's your MONGODB_URI.

2. Deploy

  1. Click Deploy above.
  2. Fill in MONGODB_URI, BETTER_AUTH_SECRET (at least 32 characters; generate it with openssl rand -base64 48), SUPPRESSION_HASH_KEY (generated the same way, another value), ADMIN_EMAILS (your email) and EMAIL_FROM (like MailCheap <[email protected]>, on a domain your Resend account or email provider verified). With a short secret, MailCheap refuses to start and the logs say why.
  3. Sign-in codes need a way to reach you. The quickest is Resend: verify EMAIL_FROM's domain there and add RESEND_API_KEY. Without it, codes go through SES or PostShiba once step 4 is done.
  4. Open https://<your-project>.vercel.app/signin and sign in with your email.

Sending stays off until you finish the next steps, so nothing goes out to readers by mistake. On any other Node.js host: npm ci && npm run build && npm start, with the same variables, behind HTTPS. /api/health answers 200, or 503 with what to fix.

If you plan to use your own domain for the dashboard (like mailcheap.example.com), add it in Vercel now and set APP_URL to it. Links in your emails use APP_URL, so it should be final before your first send.

3. Who can sign in

Only the emails you list: ADMIN_EMAILS (who can also open /admin) and ALLOWED_EMAILS, a comma-separated list of addresses and whole domains, like [email protected], @example.org. It's checked at every sign-in, with a code or with Google, and anyone you take off the list is signed out and loses their API keys at their next request. With both lists empty, nobody can sign in.

Everyone gets an account of their own, with up to 3 newsletters and their contacts and campaigns, and the account's domains and API keys. There's no billing on a self-hosted server: no plans, no limits.

To work on a newsletter together, its owner invites people from the newsletter's Team settings, up to 5, as admins or members. Invitations only go to the emails these lists let in, so add your teammates to ALLOWED_EMAILS first.

4. Email provider

Pick Amazon SES or PostShiba (invite only for now). EMAIL_PROVIDER picks one; without it, MailCheap uses PostShiba when POSTSHIBA_API_KEY is set and SES otherwise. Every account gets its own tenant there, with its own domains, suppression list and pause switch. MailCheap creates them; you set up the provider account and its events once.

Amazon SES

Use one AWS region for everything below (the examples use us-east-1). An AWS account just for MailCheap is best: SES reputation and limits are per AWS account.

  1. Request production access. New accounts are in the sandbox (200 emails a day, verified recipients only). In Account dashboard > Request production access, pick Marketing, and explain that readers opt in, that bounces and complaints are suppressed automatically, and that every email has one-click unsubscribe. AWS usually answers within a day.
  2. Create an SNS topic for events, like mailcheap-ses-events, and switch it to signature version 2, which signs messages with SHA256 instead of SHA1: aws sns set-topic-attributes --topic-arn <topic-arn> --attribute-name SignatureVersion --attribute-value 2. Then Create subscription with protocol HTTPS and endpoint https://<your-app>/api/webhooks/ses, raw message delivery off. MailCheap confirms the subscription by itself once it's deployed with the variables of step 4.
  3. Create an IAM user for MailCheap with this policy, then create an access key for it:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ses:SendEmail",
        "ses:GetAccount",
        "ses:CreateTenant",
        "ses:GetTenant",
        "ses:DeleteTenant",
        "ses:TagResource",
        "ses:CreateTenantResourceAssociation",
        "ses:DeleteTenantResourceAssociation",
        "ses:UpdateReputationEntityPolicy",
        "ses:UpdateReputationEntityCustomerManagedStatus",
        "ses:CreateConfigurationSet",
        "ses:CreateConfigurationSetEventDestination",
        "ses:DeleteConfigurationSet",
        "ses:CreateEmailIdentity",
        "ses:GetEmailIdentity",
        "ses:PutEmailIdentityMailFromAttributes",
        "ses:DeleteEmailIdentity"
      ],
      "Resource": "*"
    }
  ]
}
  1. Add the variables and redeploy: SES_REGION, SES_ACCESS_KEY_ID, SES_SECRET_ACCESS_KEY, SES_AWS_ACCOUNT_ID (the 12-digit account ID) and SES_SNS_TOPIC_ARN. Each account's configuration set publishes its events to that topic.
  2. Optional: tenant pauses. SES pauses tenants that send badly. To block the account in MailCheap too, send SES's tenant status and reputation finding events from EventBridge to a second SNS topic, subscribe https://<your-app>/api/webhooks/ses-tenants to it, and set SES_TENANT_SNS_TOPIC_ARN.

Without Resend, sign-in codes and alerts go out through SES from EMAIL_FROM, outside every tenant, so its domain has to be verified in the AWS account before your first sign-in: Identities > Create identity > Domain, with Easy DKIM. In the sandbox, the addresses you sign in with have to be verified too.

PostShiba

PostShiba approves production sending by hand: until then, sends to anyone outside your team answer kyc_required (campaigns pause with that reason) and a team can have one cluster.

  1. Team and key. In API keys, create a full access key: POSTSHIBA_API_KEY, with the team id as POSTSHIBA_TEAM_ID. Add a payment method (clusters need one).
  2. Clusters. One bulk cluster sends every email: its id goes in POSTSHIBA_BULK_CLUSTER_ID. Later, a transactional cluster in POSTSHIBA_TRANSACTIONAL_CLUSTER_ID takes welcome, confirmation and test emails, so they never wait behind a campaign. Set SEND_RATE_PER_SECOND to the bulk cluster's hourly cap divided by 3,600, less what welcome and test emails need when they share it. At a cap, PostShiba answers throttled: the batch goes back to the queue and QStash brings it after the hour.
  3. Webhook. One endpoint for the whole team (no cluster or tenant) at https://<your-app>/api/webhooks/postshiba with the events processed, delivered, deferred, bounce, dropped, spamreport and unsubscribe. Its secret goes in POSTSHIBA_WEBHOOK_SECRET.
  4. Encryption key. CREDENTIALS_ENCRYPTION_KEY, generated once with openssl rand -base64 32. It encrypts each tenant's SMTP password, and Postmaster Tools' refresh token.

MailCheap creates the rest: a tenant per account (slug mc-<accountId>), an SMTP credential for it on each cluster (one in all on a single cluster), and its domains. Creating credentials and domains and running domain checks share PostShiba's budget of 60 an hour per key; a failed setup is retried at the account's next send.

Without Resend, sign-in codes and alerts go through a tenant of their own, mc-platform, on the transactional cluster. The first one adds EMAIL_FROM's domain there, and the server log lists the two CNAME records it needs; once PostShiba finds them, codes go out. A domain belongs to one tenant at PostShiba, so EMAIL_FROM needs a domain or subdomain that no newsletter sends from.

5. QStash

  1. In the Upstash console, open QStash and copy QSTASH_TOKEN, QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY (and QSTASH_URL if you picked a region other than the default).
  2. Add them and redeploy.

QStash calls APP_URL/api/jobs/... to send each batch, so the app has to be reachable on the internet. MailCheap checks QStash's signature on every job.

6. Turn sending on

  1. In MailCheap, open Domains and add the domain your newsletter sends from. Use a subdomain like mail.example.com, so your main domain's email is unaffected. Add the DNS records it lists (DKIM, return path, and DMARC if your root domain has none), set to DNS only if your DNS is on Cloudflare, then click Check now.
  2. Create your newsletter. The from address must be on that domain, and the postal address shows in every email's footer (anti-spam laws require one).
  3. Set SENDING_ENABLED=true and redeploy.
  4. Write a campaign, send yourself a test, then send. A first send to new contacts goes out in steps by itself; for a new domain, also set a limit to reach your most engaged readers first, and use Send to more on the report once the first step looks healthy.

Optional

Sending well

Billing, as on MailCheap Cloud

MAILCHEAP_CLOUD=true is what mailcheap.ai runs with: sign-up open to anyone, a newsletter setup at /welcome right after sign-in, a dashboard to try before paying with a paywall on sending, imports, domains and API keys, plan limits, and MailCheap's own emails through Resend only. It refuses to start without STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET and RESEND_API_KEY, and /api/health answers 503 with the reason, so the cloud can't run without billing by mistake. Set MAILCHEAP_CLOUD for builds too: the public pages read it then.

Plan Monthly Yearly Emails per month Active subscribers
Starter $19 $190 20,000 10,000
Growth $39 $390 75,000 40,000
Pro $79 $790 200,000 100,000
Scale $149 $1,490 500,000 250,000
Max $349 $3,490 2,000,000 1,000,000
Ultra $799 $7,990 5,000,000 2,500,000

lib/plans.js is the one place these live. Yearly plans get the monthly allowance every month of the paid year. Every email counts toward the month: issues, tests, welcome and confirmation emails. Over a limit, campaigns stop with a clear message and an upgrade link; signups and confirmation emails keep going. Welcome emails take room in the month's emails like issues: once they're used up, each one is skipped (its Message says why), the owner gets one email that month, and the dashboard says so next to the welcome email, on the overview and on the billing page. They start again when the month resets or the plan grows; the skipped ones aren't sent later. Admin overrides replace a plan's numbers for one account.

Admins can give an account a free plan from /admin (the account's menu, Give a free plan): any of the six, with an optional end date, without Stripe. It works like a paid plan, its emails start over every month from the day it was given, and the billing page and get_billing (REST API and MCP) show it. A plan the account pays for takes over while there's one. End free plan, or its end date, stops it like a canceled plan: the data stays and sending stops.

  1. Prices by lookup key. Create six products (Starter, Growth, Pro, Scale, Max, Ultra), each with a monthly and a yearly recurring USD price, and give every price its lookup key: mailcheap_<plan>_monthly and mailcheap_<plan>_yearly, like mailcheap_growth_yearly. Checkout finds prices by these keys and refuses one whose amount or interval doesn't match lib/plans.js, so no price ID goes in the environment. A plan shows on the pricing pages, the paywall, billing and get_billing only once Stripe has both of its prices at those amounts: the app reads them every 10 minutes, and the static pages when they're built, so redeploy after adding one.
  2. Webhook. Add an endpoint at <APP_URL>/api/webhooks/stripe with the events checkout.session.completed, customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, invoice.paid and radar.early_fraud_warning.created. Use API version 2026-09-30.endive (the one stripe@23 pins) and put its signing secret in STRIPE_WEBHOOK_SECRET.
  3. Customer Portal. Turn on payment method updates, invoices, cancellation (at the end of the period) and plan changes between the twelve prices. Charge upgrades at once, with prorations invoiced immediately, and schedule downgrades, a cheaper price or a shorter interval, for the end of the period: otherwise an account can upgrade, send a bigger plan's emails and downgrade before the difference is billed. The billing page's "Switch" buttons open the portal's confirm page for one plan; without plan changes on, they open the portal's home. A blocked account gets a portal of its own, without plan changes, which MailCheap creates in Stripe the first time it's needed.

Every subscription event re-reads the subscription from Stripe, so events arriving out of order can't leave stale data. Canceled accounts keep their data: sending, signups and the website stop, and everything comes back when they subscribe again.

A blocked account isn't billed (lib/billing-pause.js): blocking pauses payment collection on its subscription, so Stripe voids its renewals while the plan, and with it the website, stays active, and invoices still waiting for payment are voided. Unblocking bills it again: from its next renewal, or, when a renewal was skipped, with a new period starting that day, charged at once. The billing page and change_plan refuse plan changes meanwhile; the Customer Portal stays open for the card, invoices and canceling, without plan changes. An account still blocked 30 days after its billing paused loses its plan: the hourly cron cancels the subscription, without a refund, and emails the owner. The same cron pauses and resumes what Stripe didn't answer at the time. Refunds stay a person's call, except one: a payment whose card's bank sends an early fraud warning is refunded at once, as fraudulent, before the chargeback that usually follows, and the plan it paid for ends.

AI agents, REST API and MCP

Create a key on the API keys page and send it as Authorization: Bearer <key>. A full access key can do everything the dashboard can; a signups only key can only add contacts, for keys that sit in a website's code. Every key gets 300 requests a minute.

Add a contact: POST /api/v1/contacts

curl -X POST https://<your-app>/api/v1/contacts \
  -H "Authorization: Bearer $MAILCHEAP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","source":"website","ip":"203.0.113.7"}'

MCP: connect Claude Code with a full access key. Every action is a tool.

claude mcp add --transport http --scope user mailcheap https://<your-app>/mcp \
  --header "Authorization: Bearer $MAILCHEAP_API_KEY"

ChatGPT, Claude and Grok Bot add https://<your-app>/mcp as a connector or custom MCP server and sign in with OAuth: you sign in to MailCheap and allow the app on a consent page, and it gets full access to that account. The API keys page lists connected apps and revokes them. They need the server to be reachable over HTTPS from the internet.

/docs on your server has every endpoint, the errors, the MCP setup for ChatGPT, Claude, Grok Bot, Claude Code, Codex and Cursor, and the OpenAPI document at /api/v1/openapi.json. On MailCheap Cloud, the same at mailcheap.ai/docs and https://mailcheap.ai/mcp.

Contributing

Read AGENTS.md first, whether you're a person or an AI agent: how the app is organized, MailCheap Cloud and self-hosting, the rules (no secrets or personal data in code, tests or commits), code style and tests. SECURITY.md covers what's built in and the known gaps. Issues are off, and pull requests may not be reviewed.

You need Node.js 22+ and MongoDB:

git clone https://github.com/marclou/mailcheap.git && cd mailcheap
npm install
cp .env.example .env.local   # set MONGODB_URI, BETTER_AUTH_SECRET, SUPPRESSION_HASH_KEY, ADMIN_EMAILS
npm run dev

Before a pull request, run the full suite, lint and a build:

npm test       # unit and integration tests
npm run lint
npm run build

Integration tests start a throwaway mongod per file, so mongod has to be on the PATH (or set MONGOD_PATH). They import server actions and route handlers as they are, and tests/setup replaces every outside service with the stubs in tests/stubs, so nothing reaches the network. tests/parity.test.mjs fails when an action is missing from the REST API, MCP, the OpenAPI document, the docs or the llms files.

License

GNU Affero General Public License v3.0. Copyright (C) 2026 Marc Lou.

If you change MailCheap and run it for other people, the AGPL asks you to offer them the source of your version: point the "Source code" link (SOURCE_URL in lib/site.js) at it. The one-time release before this license, 67d13b0 in github.com/marclou/mailcheap's history, stays under MIT.

Made by Marc Lou.

mailcheap (marclou/mailcheap)

正在搜索数据库…

这是什么?Mailcheap 是一个自托管新闻通讯(newsletter)应用,通过你自己的 Amazon SES 账户发送,让你撰写一期内容、发送给订阅列表并发布到网上,成本约为每千封邮件 0.10 美元。
这是托管服务,还是我自己运行的东西?它不是你注册就能用的 SaaS——而是一个需要你自己部署(部署到 Vercel 或任意 Node.js 主机)的小型 Next.js 应用,使用你自己的 MongoDB 数据库和 Amazon SES 账户。
怎么让它跑起来?创建一个免费的 MongoDB Atlas 集群,点击 Deploy to Vercel 并填写 MONGODB_URI、ADMIN_EMAIL、ADMIN_PASSWORD 和 SESSION_SECRET,然后连接 Amazon SES 和 Upstash QStash,再开启 SENDING_ENABLED。在其他 Node.js 主机上则是 npm ci && npm run build && npm start。
除了应用本身还需要哪些服务?用于联系人和统计的 MongoDB、用于发送的 Amazon SES、用于后台发送和定时任务的 Upstash QStash,以及 Vercel 之类的 Node.js 主机;Upstash Redis 和 Vercel Blob 是可选的,用于共享速率限制和图片上传。
出了问题有支持吗?没有。它被描述为一次性的开源发布,issue 已关闭,安装问题也不予解答——你需要自己 fork 并自行运行。
我的订阅者数据存在哪里?存在你自己的 MongoDB 数据库里——Mailcheap 不会让你的订阅列表经由任何第三方新闻通讯平台。
如何防止一次糟糕的发送损害我的发件人信誉?一旦退信率超过 2% 或投诉率超过 0.08%,Mailcheap 会自动暂停活动;它支持确认式订阅(confirmed opt-in),并能自动退订连续忽略多期内容的读者。
一套部署能运行多份新闻通讯吗?可以——每份通讯都有各自的发件地址、回复地址、通信地址和注册表单,同时共享一个管理员登录和一个抑制列表。
它如何处理退订和退信?它发送 RFC 8058 一键退订标头和带签名的退订页面,并通过 SNS 监听 SES 的退信/投诉事件,以保持共享抑制列表的最新状态。
公开归档能与后台管理面板隔离吗?可以,设置 ARCHIVE_HOSTS 后,期刊页面、作者页面和退订链接会放在单独的域名上,使来自编辑器的不可信 HTML 永远不会与后台面板同源。
作者
marclou
大小
7.6 MB
星标
1.7K
更新
提交Nov 06
时长
1个月
提交 · 90 天