Skip to content

Expose per-recipient SMTP replies and retry guidance #723

Closed

Description

@bbottema

Follow-up accepted 5 November 2026

Logging-only sending prepares a MIME message, but its receipt still derives recipients from the Email object's typed recipient list. Recipients supplied through raw To/Cc/Bcc headers can be missing. The receipt should use the prepared delivery list rather than assume that the typed Email list is the complete intended envelope.

Email email = mail.emailBuilder().startingBlank()
    .from("sender@example.org")
    .to("alice@example.org")
    .withHeader("Cc", "bob@example.org")
    .withSubject("Example")
    .withPlainText("Hello")
    .buildEmail();

try (Mailer mailer = mail.mailerBuilder()
        .withTransportModeLoggingOnly(true).buildMailer()) {
    MailSubmissionReceipt receipt = mailer.sync().sendMail(email);
    // The current receipt omits Bob, although the prepared message includes him.
}

Use the already prepared delivery-recipient view for the receipt. Preserve raw recipient headers, MIME recipient order, duplicate occurrences and explicit override recipients. Retain the existing rehearsal boundary for named groups in raw headers: a group can remain one entry in the planned list. This does not add provider-specific group expansion.

Acceptance remains UNKNOWN, with no invented SMTP replies, RCPT observations or delivery facts. A shared CustomMailer receipt describes SJM's prepared intent only; the callback owns its external mapping and can choose a different delivery list. Capture that intent before handing the mutable message to the callback, preserving its arguments, exception behavior and ownership.

If native recipient parsing cannot interpret a raw header, retain the existing typed/override UNKNOWN view rather than adding a new validation gate or preventing an opaque callback from receiving its input.

Reuse the completed preparation without another content read, rendering, cryptographic pass or transport acquisition. Keep ordinary validation, governance and locks. This completes the unreleased recipient-results feature rather than introducing a new application API or a released 9.x recipient-results fix.

The owning decisions are ADR 0011, ADR 0014 and ADR 0031. The separate Session integration work in #969 is outside this follow-up.


Part of #722, phase 1 of 03_SMTP_ROBUSTNESS_IMPROVEMENT_PLAN. Extends the unreleased submission-result API from #710.

Why

A failed send does not necessarily mean that no mail was accepted. Mixed recipients can receive different SMTP replies, and losing the final DATA reply leaves acceptance uncertain. Applications need those facts to decide whether to retry the whole message, retry particular recipients, or ask for human review.

Angus also deliberately throws reporting exceptions when mail.smtp.reportsuccess=true, even after complete acceptance. Simple Java Mail currently misclassifies that successful transaction; this phase corrects it.

Scope

  • Add immutable recipient results in envelope order, with original/mailbox addresses, final submission disposition, RCPT-attempt knowledge, the observed primary reply and text, and an optional enhanced status.
  • Retain existing accepted, valid-unsent and invalid recipient getters as immutable compatibility views.
  • Derive conservative transaction-level retry guidance and a known-retryable recipient list. Never resend automatically or imply exactly-once delivery.
  • Extract provider exception types structurally; normalize genuine success-reporting exceptions only when the whole transaction was accepted.
  • Keep original provider failures, missing replies, unknown final acceptance, custom mailers and third-party adapters intact.
  • Keep captured facts local to one attempt, including pooled async sends, simple batches, open connections and observers.

Acceptance

  • All-success reporting mode returns success.
  • Mixed 2xx/4xx/5xx RCPT results, final rejection and final-reply loss remain distinct.
  • Enhanced-status parsing rejects malformed or conflicting status text.
  • Ordered recipient results agree with compatibility views and remain immutable.
  • Retry guidance excludes permanent rejection and flags duplicate risk.
  • Recipient facts remain isolated to the correct attempt across concurrent pooled sends, connection reuse, invalidation and recovery.
  • Classpath/JPMS consumers and incomplete third-party provider results remain supported.
  • Existing submission-result documentation explains the API and its limits.

Phase 1 is complete and accepted. The implementation was committed as f79c66c6 and is already on the pushed codex/10.0.0 branch, with documentation included. Closing this leftover tracking item does not introduce new Phase 1 work. The changes remain unreleased until 10.0.0 ships; later steps are tracked under #722.

Activity

  1. added this to the 10.0.0 milestone on Sep 7, 2026
  2. self-assigned this
    on Sep 7, 2026
  3. moved this from Todo to In Progress in Simple Java Mail 10.0.0on Sep 7, 2026
  4. bbottema commented on Sep 17, 2026

    @bbottema
    OwnerAuthor

    This was already accepted and pushed for 10.0.0; closing the leftover tracking issue.

    Use receipt.getRecipientResults() for each recipient's observed reply and disposition, and receipt.getRetryDisposition() / getRetryableRecipients() for conservative retry guidance. A missing final DATA reply remains uncertain and can mean duplicate risk; no automatic retry is performed.

    Usage and sample output. The remaining roadmap stays under #722.

  5. moved this from In Progress to Done in Simple Java Mail 10.0.0on Sep 17, 2026
  6. moved this from Done to In Progress in Simple Java Mail 10.0.0on Nov 5, 2026
  7. bbottema commented on Nov 8, 2026

    @bbottema
    OwnerAuthor
    SimpleJavaMail mail = SimpleJavaMail.fromDefaults();
    
    Email email = mail.emailBuilder().startingBlank()
        .from("sender@example.org")
        .to("alice@example.org")
        .withHeader("Cc", "bob@example.org")
        .withSubject("Example")
        .withPlainText("Hello")
        .buildEmail();
    
    try (Mailer mailer = mail.mailerBuilder()
            .withTransportModeLoggingOnly(true)
            .buildMailer()) {
        MailSubmissionReceipt receipt = mailer.sync().sendMail(email);
        for (MailRecipientResult recipient : receipt.getRecipientResults()) {
            System.out.println(recipient.getOriginalAddress());
        }
    }

    The recipient list now includes both Alice and Bob, including Bob's raw Cc header. Logging-only receipts describe the prepared recipients with UNKNOWN acceptance and no invented SMTP replies.

    CustomMailer receipts capture the same prepared intent before the callback runs; the callback still owns its external delivery mapping. Explicit override recipients retain their order.

    Completed on the 10.0.0 development branch in the prepared-recipient correction, alongside the earlier per-recipient replies and retry guidance. See ADR 0011 and ADR 0014 for the outcome and planned-recipient boundaries. This remains unreleased until 10.0.0 ships.

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