Skip to content

Add DSN envelope identifiers for send correlation #736

Closed

Description

@bbottema

Part of #722, Phase 4 step 6. Extends delivery-status notification support from #574; related to recipient results in #723 and capability diagnostics in #733.

Why

A later bounce or delivery-status notification needs to be matched to the particular send that caused it. ENVID supplies an SMTP transaction identifier that a DSN can return as Original-Envelope-ID. It is separate from the MIME Message-ID, and does not alter exact or signed message content.

This neither guarantees a notification or final delivery nor adds a mailbox reader or automatic bounce-processing service.

Approved scope

ENVID only. Recipient-specific NOTIFY and automatic ORCPT are tracked separately in #738, under #722. That follow-up is complete under its own issue through the managed Angus command hook; it is not part of this issue. No upstream Angus release is needed for either implementation.

  • By default, generate a fresh UUID for each send on a DSN-capable connection. Reusing or concurrently sending the same Email produces separate identifiers; generated values are never written back onto Email.
  • Expose the effective unencoded identifier through MailSubmissionReceipt.getEnvelopeId(), also available through the observer's receipt. Failed SMTP attempts can retain an identifier actually used for MAIL FROM; its presence does not establish acceptance. Local failures before MAIL FROM report no identifier. Return null when use is absent or unknown.
  • Let composed and exact Email builders override this with fixingEnvelopeId(...). Null resumes automatic behavior. Preserve fixed values through partial DSN updates, copying and whole-value Email defaults/overrides. Reusing a fixed value deliberately reuses that identifier.
  • Validate fixed identifiers before acquiring SMTP resources: non-empty printable ASCII, at most 94 xtext characters for the value (100 including ENVID=). Do not trim or replace the caller's value.
  • Check DSN on the actual send connection after TLS/authentication. Automatic generation is best-effort: without usable DSN, send normally without ENVID. A fixed identifier is required: reject before MAIL FROM if unsupported. Existing NOTIFY/RET remain best-effort.
  • Use Angus's supported per-message MAIL extension hook. Preserve unrelated raw parameters. Existing raw ENVID suppresses automatic generation and remains caller-owned, without receipt reporting; raw ENVID plus a typed fixed value is rejected.
  • Keep identifiers isolated across synchronous/asynchronous, pooled, batch and open-connection sends. Preserve MIME content and receipt/observer ordering.
  • Require third-party adapters to opt in to fixed ENVID support and report effective identifiers through MailTransportResult.withEnvelopeId(...). Older adapters retain ordinary sends without automatic ENVID. CustomMailer receives fixed values on Email and owns transport mapping/enforcement; Simple Java Mail does not generate or report ENVID for that caller-owned transport. Logging-only also reports none.
  • Expose --email:fixingEnvelopeId and --email:fixingExactEnvelopeId in the CLI. No global property or Spring metadata default is appropriate for a per-send identifier; Spring applications use the same Email API.

Usage

MailSubmissionReceipt receipt = mailer.sync().sendMail(email);
String envelopeId = receipt.getEnvelopeId(); // null when unavailable

// Optional: use an application-owned identifier instead.
emailBuilder.fixingEnvelopeId("order-42-attempt-1");

Progress

Complete, accepted and pushed to codex/10.0.0, with the matching website guidance on codex/10.0.0-content. This is unreleased 10.0.0 work. The architecture overview remains accurate: no new worker, lock or resource owner was introduced. Together with #738 this completes the DSN step; the rest of Phase 4 remains open under #722.

Acceptance

  • Provider feasibility characterized and the narrower scope approved.
  • Automatic and fixed API, validation, copy/governance and serialization coverage.
  • Wire encoding, best-effort automatic fallback and strict fixed-ID rejection.
  • Pooled concurrency, subsequent sends, shared connections, batches and observer/receipt identity.
  • Exact/protected MIME bytes remain unchanged; ambiguous submission retains its identifier without claiming acceptance.
  • CLI, classpath/JPMS and provider boundaries covered; configuration/Spring exclusions documented.
  • User guidance, migration note, release notes and architecture overview updated.
  • Implementation accepted, selectively committed and pushed with matching website documentation.

References: RFC 3461 ENVID, RFC 3464 Original-Envelope-ID, Angus MAIL extension API, Angus 2.0.5 SMTPTransport.

Activity

  1. added this to the 10.0.0 milestone on Sep 15, 2026
  2. self-assigned this
    on Sep 15, 2026
  3. changed the title [-]Add DSN envelope identifiers and original-recipient support[/-] [+]Add DSN envelope identifiers for send correlation[/+] on Sep 15, 2026
  4. bbottema commented on Sep 17, 2026

    @bbottema
    OwnerAuthor

    Implemented for 10.0.0:

    MailSubmissionReceipt receipt = mailer.sync().sendMail(email);
    String envelopeId = receipt.getEnvelopeId(); // null when unavailable

    The bundled Angus adapter supplies a fresh identifier for each DSN-capable send. Use emailBuilder.fixingEnvelopeId("order-42-attempt-1") when you need your own value; fixed identifiers require DSN support. The receipt reports an identifier only when the submission used it, not for a local failure before MAIL FROM.

    Match it to a later notification's Original-Envelope-ID; it is separate from Message-ID and does not prove delivery. Usage and sample output.

  5. moved this from In Progress to Done in Simple Java Mail 10.0.0on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions