Repository navigation
email-queue 0.2.0: suppression, bulk, breaker, quota and SMTP gates - #177
Merged
Merged
Conversation
…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]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens
@profullstack/email-queueso it can gate automated outbound, per the audit at 58bda48. Bumps the package to 0.2.0. Nothing is published, deployed, or sent.Items
queueEmailandqueuedDelivery. Adds theemail_queue_recipient_suppressionstable, with an idempotentmigrate()that also backfills from the old per-provider table. Adds a Redis store soqueuedDeliverywithout Postgres (MyNaPoster) still honors suppressions. New:suppress(),getSuppression(),handleUnsubscribe()(RFC 8058 one-click POST + mailto), signedcreateUnsubscribeToken/verifyUnsubscribeToken,listUnsubscribeHeaders(). Webhook suppressions now write the shared table, and SMTP 550 5.1.1 hard bounces auto-suppress.kind: "bulk" | "marketing"is refused unless it has aList-Unsubscribeheader with an https URL,List-Unsubscribe-Post: List-Unsubscribe=One-Click, and thepostalAddressoption, 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.providerId, which pauses every identity on that credential. It never reroutes.resumeEmailQueueclears both breakers.UNKNOWN. New optionalmaxRecipientDomainPer24Hoursscope.auditStoreis set.redactError()runs on every stored error: Resend bodies, worker results,UNKNOWNtext, and the Postgreserrorcolumns. It removes emails, credentials, key prefixes, JWTs, long tokens, and URL query strings, and caps the text at 300 characters.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 withSENDER_UNAUTHORIZED.authorizedSendersis 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 bothEMAIL_QUEUE_REDIS_URLandEMAIL_QUEUE_ENCRYPTION_KEYare set. Otherwise the direct path is unchanged, so nothing breaks today. Newsletters pass their postal address to the bulk gate.emailQueueConfigProblems()/assertEmailQueueConfig(). The MyNaPoster API server and daemon now log a missing or invalidEMAIL_QUEUE_ENCRYPTION_KEYat startup. The per-send failure isCONFIG_INVALIDwith 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)
EmailAuditStoreimplementations must addsuppress()andgetSuppression().isSuppressed()is now optional and deprecated.EmailKindadds"marketing".Test results
Run against a throwaway
redis:7container (EMAIL_QUEUE_TEST_REDIS_URL), which was removed afterwards:bun x tsc --noEmit -p tsconfig.json: cleanbun 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. Newtest/gates.test.tscovers:apps/api/test: 950 pass, 27 skip, 0 fail (977 tests, 129 files)Not in this PR
EMAIL_QUEUE_ENCRYPTION_KEYis 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.🤖 Generated with Claude Code