Skip to content

email-queue 0.2.0: suppression, bulk, breaker, quota and SMTP gates - #177

Merged
sh1pt-actions-fleet[bot] merged 1 commit into
mainfrom
fix/email-queue-gates
Nov 2, 2026
Merged

sh1pt-actions-fleet[bot] merged 1 commit into
mainfrom
fix/email-queue-gates

Conversation

@sh1pt-actions-fleet

Copy link
Copy Markdown
Contributor

Hardens @profullstack/email-queue so it can gate automated outbound, per the audit at 58bda48. Bumps the package to 0.2.0. Nothing is published, deployed, or sent.

Items

  1. Provider-agnostic suppression. Keyed by the normalized recipient; the provider is stored as metadata only. Checked at enqueue and again in the worker right before send, on both queueEmail and queuedDelivery. Adds the email_queue_recipient_suppressions table, with an idempotent migrate() that also backfills from the old per-provider table. Adds a Redis store so queuedDelivery without Postgres (MyNaPoster) still honors suppressions. New: suppress(), getSuppression(), handleUnsubscribe() (RFC 8058 one-click POST + mailto), signed createUnsubscribeToken/verifyUnsubscribeToken, listUnsubscribeHeaders(). Webhook suppressions now write the shared table, and SMTP 550 5.1.1 hard bounces auto-suppress.
  2. Bulk/marketing gate. kind: "bulk" | "marketing" is refused unless it has a List-Unsubscribe header with an https URL, List-Unsubscribe-Post: List-Unsubscribe=One-Click, and the postalAddress option, with the address present in both the text and HTML bodies. Codes: BULK_LIST_UNSUBSCRIBE_MISSING, BULK_ONE_CLICK_MISSING, BULK_POSTAL_ADDRESS_NOT_CONFIGURED, BULK_POSTAL_ADDRESS_MISSING.
  3. Breaker. Pauses the sender identity on any 401/403, a suspended account, an invalid key, an unverified domain, SMTP 530/534/535/538, or any SMTP 5.7.x. Account-level failures (401, suspended, invalid key) also open a breaker on the providerId, which pauses every identity on that credential. It never reroutes. resumeEmailQueue clears both breakers.
  4. Quota. The quota is refunded when a message definitely did not go out: a worker-side gate refused it, the provider refused it, or the enqueue failed. It stays spent for UNKNOWN. New optional maxRecipientDomainPer24Hours scope.
  5. queuedDelivery. When no key is given, the idempotency key is derived from identity + recipient + SHA-256(subject, text, html), so keyless transactional sends no longer get a random UUID. This is documented: an identical resend within 30 days returns the earlier receipt. The Postgres audit is written when auditStore is set.
  6. Redaction. redactError() runs on every stored error: Resend bodies, worker results, UNKNOWN text, and the Postgres error columns. It removes emails, credentials, key prefixes, JWTs, long tokens, and URL query strings, and caps the text at 300 characters.
  7. SMTP transport. createSmtpTransport() uses nodemailer, which is added as a dependency and loaded lazily. From and the envelope are pinned to the authenticated mailbox. A different From is refused locally with SENDER_UNAUTHORIZED. authorizedSenders is enforced when the transport is built. From/Sender/Return-Path/Reply-To/To/Cc/Bcc headers are dropped, and CR/LF are stripped from header values. nodemailer errors are mapped to reply code + enhanced status. In MyNaPoster (packages/core/src/core/mail/index.ts), non-Google SMTP goes through the queue only when both EMAIL_QUEUE_REDIS_URL and EMAIL_QUEUE_ENCRYPTION_KEY are set. Otherwise the direct path is unchanged, so nothing breaks today. Newsletters pass their postal address to the bulk gate.
  8. Missing encryption key / README. New emailQueueConfigProblems() / assertEmailQueueConfig(). The MyNaPoster API server and daemon now log a missing or invalid EMAIL_QUEUE_ENCRYPTION_KEY at startup. The per-send failure is CONFIG_INVALID with the env var name and how to generate the key. The README covers required env, a release-gate checklist, and upgrade notes.

Breaking (0.x minor)

  • EmailAuditStore implementations must add suppress() and getSuppression(). isSuppressed() is now optional and deprecated.
  • Non-compliant bulk mail is refused.
  • More failure types pause the sender.
  • EmailKind adds "marketing".

Test results

Run against a throwaway redis:7 container (EMAIL_QUEUE_TEST_REDIS_URL), which was removed afterwards:

  • bun x tsc --noEmit -p tsconfig.json: clean
  • bun run build (packages/email-queue): clean. The built dist loads nodemailer lazily and maps a refused connection to status 0.
  • bun test packages/email-queue/test: 56 pass, 0 fail. New test/gates.test.ts covers:
    • suppression from one provider blocking another provider at enqueue, and again at worker time after enqueue, with a quota refund
    • bulk rejection for each code
    • the breaker on Resend 403, on Resend 401 (account-wide), and on SMTP 535 and 550 5.7.1
    • no pause on 5.1.1, and auto-suppression on it
    • quota refund vs. UNKNOWN
    • the recipient-domain cap
    • keyless dedupe plus the audit write
    • redaction in Resend errors and in the Postgres store
    • SMTP From/envelope pinning, header-injection drop, and authorizedSenders
    • one-click/mailto unsubscribe and token tampering
    • schema migration/backfill
  • Full release.yml suite plus apps/api/test: 950 pass, 27 skip, 0 fail (977 tests, 129 files)

Not in this PR

  • No npm publish, no deploy, and no env changes. EMAIL_QUEUE_ENCRYPTION_KEY is still unset in the deployed containers. Until it is set, MyNaPoster's Resend/Gmail sends keep failing closed (now logged at startup) and SMTP stays on the direct path.
  • OutreachGraph adoption is a separate PR in that repo.
  • Other HTTP providers in MyNaPoster (Mailgun, Postmark, SES, ...) still send directly.

🤖 Generated with Claude Code

…0.2.0)

Make @profullstack/email-queue safe enough to gate automated outbound:

- Suppression keyed by normalized recipient (provider is metadata), checked
  at enqueue AND in the worker right before send, on queueEmail and
  queuedDelivery. Postgres table email_queue_recipient_suppressions
  (idempotent migrate + backfill) and a Redis store for callers without
  Postgres. suppress(), getSuppression(), handleUnsubscribe() (RFC 8058
  one-click POST + mailto), signed unsubscribe tokens. SMTP 5.1.1 hard
  bounces auto-suppress.
- Bulk/marketing gate: List-Unsubscribe https + List-Unsubscribe-Post
  One-Click + configured postalAddress present in text and HTML. Coded
  errors (EmailQueueError / DeliveryResult.code).
- Breaker pauses on any 401/403, suspended account, unverified domain,
  SMTP 530/534/535/538 and any 5.7.x; account-level failures pause every
  identity on the provider credential. Never reroutes.
- Quota refunded on definite non-delivery (gate refusal in worker, provider
  refusal, failed enqueue), kept for UNKNOWN. Optional
  maxRecipientDomainPer24Hours scope.
- queuedDelivery: deterministic content-derived key for keyless
  transactional sends, Postgres audit when a store is configured.
- redactError() on every stored provider error.
- createSmtpTransport (nodemailer): From/envelope pinned to the
  authenticated mailbox, authorizedSenders enforced, header injection
  blocked, error mapping for the breaker.
- emailQueueConfigProblems()/assertEmailQueueConfig(); mynaposter logs
  them at API/daemon startup.
- mynaposter: non-Google SMTP goes through the queue only when both
  EMAIL_QUEUE_REDIS_URL and EMAIL_QUEUE_ENCRYPTION_KEY are set (direct
  path unchanged otherwise); newsletters pass their postal address.
- README: required env, release-gate checklist, upgrade notes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​nodemailer@​8.0.21001007688100
Addednodemailer@​10.3.1981009896100

View full report

@sh1pt-actions-fleet
sh1pt-actions-fleet Bot merged commit e8cc01f into main Nov 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant