Skip to content

feat(dms-mailing): send template e-mails with attachments - #201

Merged
Upd4ting merged 3 commits into
mainfrom
feat/template-attachments
Nov 20, 2026
Merged

Upd4ting merged 3 commits into
mainfrom
feat/template-attachments

Conversation

@mwesto

@mwesto mwesto commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

W05057e83-10. SendTemplate now carries attachments. @antelopejs/interface-email already accepts files, but SendTemplate had nowhere to put them, so Altab could not attach its invoice PDFs. Taken over from Maxime's first version and cut down to the pass-through, per the CTO review.

  • Interface. SendTemplateParams.attachments?: SendAttachment[], with SendAttachment { filename, contentType?, content: Uint8Array }. A Buffer is a Uint8Array.
  • Delivery. prepare turns the files into interface-email BufferAttachments once. messageFor passes them to Send and SendBatch for every recipient.
  • One fixed ceiling. At most 10 files, adding up to at most 10 MiB. Over that, the call rejects with code attachments_too_large before anything is sent or logged.
  • File name. The module keeps the last path segment and strips CR and LF, so a name cannot start a header of its own.
  • Send log. The new optional field json_attachments keeps each file's name, type, size and SHA-256, never its bytes. It is written for every recipient, suppressed ones included.
  • Replay. Send again and fix address refuse a send that carried files with 409 $dms_mailing.errors.no_replay_with_attachments. The drawer footer offers neither for such a send.
  • Drawer. The send drawer lists each file's name and size.
  • SendError moves to services/send-error.ts so services/attachments.ts can throw it without pushing send.ts past the 500-line lint cap.

Cut from the first version

GetSendCapabilities and SendCapabilities, SendErrorCode, the provider features.attachments probe, the maxAttachments and maxAttachmentBytes module options, the zod schema, grapheme segmentation, bidi stripping, the 200-grapheme cut, the MIME regex, the multipart and message refusal, the send-from-code attachments journey (the integration test covers the same path in-process), and the test SMTP recorder (main's helpers/mail-store already keeps every raw message).

⚠ sensitive: adds the stored field json_attachments to mailing_sends and a field to the public SendTemplateParams contract

Release

Release @antelopejs/interface-dms-mailing first, then the module. No migration: json_attachments is optional, and old rows have none.

Proof

src/test/integration/send-attachments.test.ts runs the real nodemailer transport against the SMTP fixture and reads the raw messages.

Before, on main with the same test file (the type errors are expected: attachments does not exist there yet):

  0 passing (942ms)
  4 failing
  1) delivers the file over SMTP and logs its name, size and hash only:
     ZodError: expected array, received null        (no json_attachments)
  2) logs the files of a suppressed recipient without sending them:
     ZodError: expected array, received null
  3) refuses a file over the ceiling before anything is logged:
     AssertionError: expected { …(5) } to have property 'code'   (11 MiB file sent)
  4) refuses to send again a send whose files the log does not keep:
     AssertionError: expected 200 to equal 409

After, on this branch:

    ✔ delivers the file over SMTP and logs its name, size and hash only
    ✔ logs the files of a suppressed recipient without sending them
    ✔ refuses a file over the ceiling before anything is logged
    ✔ refuses to send again a send whose files the log does not keep
  4 passing (787ms)

Also run locally: pnpm run typecheck, oxlint, oxfmt --check, the frontend lint, the layer tests attachments, send-drawer and send-actions (26 passing), unit/send.test.js (12 passing), and the integration files send-failures, send-figures, send-import, send-lifecycle, send-tallies and sends (all passing).

flowchart LR
  A["SendTemplate(slug, { attachments })"] --> B{"checkAttachments: over 10 files or 10 MiB?"}
  B -- yes --> R["reject attachments_too_large, nothing sent or logged"]
  B -- no --> C["BufferAttachment[]: last path segment, no CR/LF"]
  C --> D["messageFor → interface-email Send / SendBatch"]
  C --> E["send row: json_attachments = name, type, size, SHA-256"]
  E --> F["POST /sends/:id/replay → 409 no_replay_with_attachments"]
Loading

Follow-ups

  • none

mwesto and others added 3 commits November 20, 2026 14:32
Keep SendTemplateParams.attachments, their pass-through to the email
provider, one fixed ceiling (10 files, 10 MiB), the file name's last path
segment without line breaks, the json_attachments log summary, the 409 on a
replay and the file list in the send drawer.

Drop GetSendCapabilities and SendCapabilities, SendErrorCode, the provider
features probe, the maxAttachments and maxAttachmentBytes options, the zod
schema, the grapheme, bidi, MIME type and multipart rules, the journey
(the integration test covers it) and the test SMTP recorder, which main's
mail store replaces.
@Upd4ting
Upd4ting force-pushed the feat/template-attachments branch from 3bd99a1 to 71a020e Compare November 20, 2026 14:43
@Upd4ting
Upd4ting added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit d2f6db5 Nov 20, 2026
13 checks passed
@Upd4ting
Upd4ting deleted the feat/template-attachments branch November 20, 2026 18:05
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.

2 participants