Skip to content

Make Mailer execution mode explicit with sync and async views #734

Closed

Description

@bbottema

Why

Choosing sync or async should be visible at the operation call. A Mailer-wide default and several overlapping send methods make it too easy to hide whether a call blocks or returns pending work. In 10.0.0, require explicit selection and return the existing submission receipt from every single-email send; callers can ignore it.

This is a separate enhancement under #722, coordinated with the unfinished SMTP probe in #733. Completed Phase 2 issues stay closed.

API

mailer.sync().sendMail(email); // ignore the receipt when only completion matters
MailSubmissionReceipt receipt = mailer.sync().sendMail(email);
MailSend<MailSubmissionReceipt> send = mailer.async().sendMail(email);

The nested Mailer.Sync and Mailer.Async views each expose sendMail, sendMailsInSimpleBatch, and testConnection. The probe operations will be added to these views separately in #733. Single sends return receipts; simple batches stay lazy, sequential, first-failure-stopping and completion-only. Per-email batch outcomes remain available through the observer.

Remove builder .async(), isAsync(), the backing mode field, all flat/default-driven/boolean-execution-mode Mailer operations, and the separate receipt-specific send family. No deprecated forwarding aliases. Keep scoped MailSender, configuration, rehearsal, validation, queue inspection, open-connection callbacks and lifecycle APIs unchanged. Existing integrations must recompile and migrate deliberately.

The cached views share the owning Mailer's lifecycle, executor and pool. Preserve preparation/admission threads, cancellation, deadlines, observer and cleanup ordering, receipt identity, and exception semantics. Resource properties and Spring support are unchanged: execution mode is a choice made by application code, not a configuration default.

CLI send/connect use the synchronous view; daemon request concurrency stays daemon-owned. Remove and clearly reject --mailer:async and its option help. CLI probing remains separate in #733.

Implementation and review

  • Implement views and remove the old mode-selecting API and receipt-discarding wrapper.
  • Migrate integrations, CLI, demos, tests, public API consumers and current 10.0.0 documentation.
  • Verify positive/negative API compilation, shared resources, receipts/failures, queue/cancellation/observer/batch regressions, CLI and supported Java/Spring lanes.
  • Review production diffs and retain the probe review bookmark.

Accepted on 13 September 2026 and committed and pushed independently of the probe. The migration covers the existing send, simple-batch and connection-test families, their consumers and current 10.0.0 documentation. The probe's types, entry points, implementation and documentation remain uncommitted under #733.

Follow the root API expansion and coding guides. Preserve historical docs, staged research and unrelated Journal work. Keep #733 open and do not mark Phase 3 complete. The send architecture infographic remains accurate because its implementation layers and resource ownership do not change.

Accepted plan and probe-review bookmark.

Activity

  1. added this to the 10.0.0 milestone on Sep 12, 2026
  2. moved this from In Progress to Done in Simple Java Mail 10.0.0on Sep 13, 2026
  3. bbottema commented on Sep 13, 2026

    @bbottema
    OwnerAuthor

    Implemented for 10.0.0. Choose execution mode at the call:

    mailer.sync().sendMail(email); // receipt is optional to inspect
    MailSend<MailSubmissionReceipt> send = mailer.async().sendMail(email);

    The builder async default and old flat/boolean send methods are removed. Simple batches remain streaming and completion-only. SMTP probing is tracked separately in #733.

  4. 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-10-27: Honor CLI help before later removed execution options

    A removed CLI option after a genuine help request can replace the requested help with a migration error.

    sjm send --help --mailer:async
    

    This currently reports that --mailer:async was removed. The command should show help successfully and ignore later arguments, as it already does for ordinary malformed options after help. Keep the migration error when the removed option comes before help or is supplied alone:

    sjm send --mailer:async --help
    sjm send --mailer:async
    

    Apply the existing generated-model help cutoff before checking removed execution-mode options. Standard --help, -h and registered option-specific help follow the same ordering rule. Literal values that happen to end in --help, end-of-options handling, one-shot and daemon routing, and argument-file expansion keep their existing meanings. Help must not execute builders, read message content or acquire a Mailer.

    The maintainer approved this correction under ADR 0018, continuing the help distinction established in #841. No option names or public Java APIs change.

    Acceptance requires help to win over every later removed-option spelling while earlier or standalone removed options retain their migration diagnostic. Ordinary help/value behavior and request routing remain consistent.

    Completed behavior — 2026-10-27

    sjm send --help --mailer:async
    # Displays help successfully.
    
    sjm send --mailer:async --help
    # Reports that --mailer:async was removed.
    

    Delivered on the 10.0.0 development branches. Standard and registered option-specific help ignore later removed execution-mode options. An earlier or standalone removed option keeps its migration diagnostic.

    The existing command model still distinguishes genuine help from literal values, and argument-file and local/daemon routing retain their contracts. Help does not execute builders, read message content or acquire a Mailer. No flags, escaping rules or metadata format changed.

    Implementation: cf3e5441, with documentation alignment in 70d3cf26. Website guidance: ac0c156. Decision: ADR 0018. Version 10.0.0 remains unreleased.

    2026-10-27: Keep retired CLI option spellings usable as literal message values

    The CLI rejects a literal message value when it happens to match a removed execution option.

    sjm validate --email:startingBlank --email:from sender@example.test --email:to recipient@example.test --email:withSubject "--mailer:async=false" --email:withPlainText body --mailer:withSMTPServer smtp.example.test 25
    

    This reports that --mailer:async was removed instead of using --mailer:async=false as the subject. The same text should remain usable in subjects, bodies and header values, just like other unregistered option-shaped values.

    Let Picocli determine which arguments are values and which are unmatched options. Apply the existing migration diagnostic only when a retired execution option is actually unmatched. Keep the error for standalone retired options and those before a genuine help request; help still ignores later arguments. Standard parser errors, repeated builder calls, one-shot execution and daemon execution retain their existing behavior. No new option, escaping syntax or Java API is needed.

    The maintainer approved this correction under ADR 0018, continuing the literal-value contract in #841 and help ordering in #734.

    Acceptance requires each retired spelling to pass unchanged when consumed as a subject, body or header value, while actual retired options keep their migration error and help ordering.

    Completed behavior — 2026-10-27

    sjm validate --email:startingBlank --email:from sender@example.test --email:to recipient@example.test --email:withSubject "--mailer:async=false" --email:withPlainText body --mailer:withSMTPServer smtp.example.test 25
    

    The subject now stays --mailer:async=false. The same retired spellings remain usable as body and header values when Picocli consumes them as values. Actual retired options keep their migration error and existing help ordering.

    Available on the 10.0.0 development branch in the CLI change and the usage guide, following ADR 0018.

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