Skip to content

Submit finalized EML without rebuilding its MIME content #713

Closed

Description

@bbottema

Why

Simple Java Mail can parse EML into an Email, but sending that result rebuilds the MIME message. That is correct for normal editing and composition, but wrong when the caller already has a finalized wire message whose bytes matter.

Typical examples are relaying an archived message, submitting output from another MIME generator, or sending content that already carries DKIM, S/MIME or OpenPGP/MIME signatures. Parsing and rebuilding can change headers, folding, MIME boundaries, line endings or signed bytes.

Proposed direction

Add an advanced Mailer API for submitting finalized EML bytes without reconstructing the MIME content. The caller should provide:

  • the exact EML bytes or an InputStream;
  • explicit SMTP envelope recipients;
  • an optional envelope sender/bounce address;
  • delivery options that belong to the SMTP envelope rather than MIME content.

The API should use the normal Simple Java Mail transport path, including proxying, pooling, transport adapters, receipts and synchronous/asynchronous execution. It should not apply Email defaults or overrides, rewrite headers, resolve embedded images, or add DKIM/S/MIME/OpenPGP processing. The content is already final.

Envelope recipients must be explicit instead of inferred only from To/Cc headers: Bcc recipients may not appear in the EML at all, and relay workflows often deliberately use an envelope that differs from the visible headers.

Questions to settle

  • What should the public type and method names be: submitEml, FinalizedMail, or something else?
  • Can the selected Jakarta Mail provider send the supplied bytes without calling code that normalizes the MimeMessage? The contract needs real Angus integration tests, especially for signed content.
  • Should malformed EML be rejected early, or passed through as long as a minimally usable MimeMessage can be created?
  • How should the configured maximum message size apply? Checking the supplied wire-byte length is the least surprising behavior.
  • Who owns and closes a supplied InputStream?
  • Which receipt fields can be populated without modifying the message, particularly when it has no Message-ID?

If exact preservation cannot be guaranteed for a provider, the API must fail clearly or document that provider as unsupported. Silently rebuilding the content would defeat the feature.

This should build on #710 and #711 rather than introducing separate receipt or async conventions.

Related history

#460 is the direct predecessor to this feature. It reported that parsing and resending EML changed MIME boundaries and broke an upstream DKIM signature. The discussion concluded that rebuilding an Email could never preserve the original message and proposed a future Mailer.relay(MimeMessage) API. #706 later established exact-byte preservation through FinalizedMimeMessage for signed EML conversion.

Activity

  1. added this to the 10.0.0 milestone on Aug 25, 2026
  2. moved this from Todo to In Progress in Simple Java Mail 10.0.0on Aug 27, 2026
  3. moved this from In Progress to Done in Simple Java Mail 10.0.0on Aug 27, 2026
  4. bbottema commented on Aug 27, 2026

    @bbottema
    OwnerAuthor

    Implemented for 10.0.0.

    Email email = mail.emailBuilder()
        .startingFromExactEml(Files.readAllBytes(Path.of("ready-to-send.eml")))
        .withEnvelopeRecipients("actual-recipient@example.org")
        .withEnvelopeSender("bounces@example.org") // optional
        .buildEmail();
    
    MailSubmissionReceipt receipt = mailer.sendMailAndGetReceiptSync(email);

    Email remains the canonical type and works with the existing synchronous, asynchronous, batch, pooled, open-connection, rehearsal, observer, and custom-mailer APIs. Its getters expose the parsed message while conversion and submission use the copied EML bytes unchanged. The CLI accepts the EML file through --email:startingFromExactEml.

  5. bbottema commented on Nov 1, 2026

    @bbottema
    OwnerAuthor

    Development addenda for unreleased 10.0.0

    These follow-ups complete this feature's 10.0.0 implementation. Dates identify the original development records; before examples describe earlier development revisions.

    2026-11-01: Expose truthful protection inspection for exact EML

    Exact EML construction exposes ordinary Email inspection getters, but protected input currently receives plain defaults. An encrypted S/MIME message can report NOT_ENCRYPTED, and a signed OpenPGP message can report no signature, even though neither fact was established.

    Email exact = mail.emailBuilder().startingFromExactEml(encryptedSmimeEml)
        .withEnvelopeRecipients("recipient@example.org")
        .buildEmail();
    
    OriginalSmimeDetails details = exact.getOriginalSmimeDetails();

    Populate the existing protection getters automatically from available receive-side inspection. Recognize declared signed/encrypted envelopes and use UNKNOWN for facts inspection cannot establish. Keep precise results such as VALID, KEY_MISSING or FAILED when actually established. Missing optional cryptography support must not by itself prevent exact relay.

    Reuse feature-owned inspection without adding an inspection switch, new public result type or receive-key API. Keep the existing parsed content/header view and explicit envelope rules, caller stream ownership, canonical-input validation, locks, templates bypass and exact-source authority intact. Getters remain passive. Do not apply outgoing signing/encryption, image resolution or MIME reconstruction as part of inspection.

    The original bytes remain the sole sending/rehearsal/export authority, including Bcc and original signatures. Ordinary copying retains its existing loss-of-exact-authority boundary; supported serialization retains source bytes and inspection results. Handle inspection absence/incomplete input truthfully without swallowing unrelated programming or required-content failures.

    This correction targets the 10.0.0 development branch and follows ADR 0013, ADR 0008 and ADR 0035.

    Completed behavior — 2026-11-01

    Email exact = mail.emailBuilder().startingFromExactEml(originalEml)
        .withEnvelopeRecipients("receiver@example.org")
        .buildEmail();
    
    System.out.println(exact.getOriginalSmimeDetails().getVerificationStatus());
    System.out.println(exact.getOriginalOpenPgpDetails().getSignatureStatus());

    The existing protection getters now contain the facts established during exact construction by available incoming inspection. Unavailable or inconclusive inspection leaves unestablished facts UNKNOWN, including signature facts inside unopened ciphertext, while actual signature, missing-key and failure outcomes keep their precise states. Exact construction supplies no receiving keys; ordinary conversion remains the route for explicit keys and an opened, editable view.

    The raw parsed body, headers and attachments stay intact, and the original EML remains authoritative for export, rehearsal and submission. Getter reads remain passive. Keep the original EML for relay independent of optional modules; restoring a Java snapshot still needs its producer result classes and modules.

    Delivered on the unreleased 10.0.0 development branch in 0666e732, following ADR 0013 and ADR 0008.

    The accompanying guidance is delivered in 1bead024 and the website companion. Incoming interpretation also follows ADR 0035.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions