Skip to content

Use the selected protocol's username for pooled OAuth connections #966

Closed

Description

@bbottema

An SMTPS Session can contain a different username for unused SMTP configuration. With the batch module present, the underlying pool selects that unused SMTP username when opening an OAuth connection. The direct connection path uses the selected SMTPS account instead.

This affects published 9.3.9. Its fixed-token API can reach the problem without an access-token callback:

Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", "smtps");
properties.setProperty("mail.smtps.host", "smtp.example.org");
properties.setProperty("mail.smtps.user", "current@example.org");
properties.setProperty("mail.smtps.auth.mechanisms", "XOAUTH2");
properties.setProperty("mail.smtp.user", "old@example.org");
properties.setProperty(
    TransportStrategy.OAUTH2_TOKEN_PROPERTY, "current-account-token");

try (Mailer mailer = MailerBuilder
        .usingSession(Session.getInstance(properties))
        .buildMailer()) {
    mailer.sendMail(email);
}

The selected SMTPS connection should authenticate as current@example.org. Adding pooling must not make the inactive mail.smtp.user setting authoritative. Keep both Session properties intact, preserve the selected provider's ordinary username fallback, and apply the same selection to fixed tokens and connection-time providers, including reconnections.

SMTP Connection Pool #38 owns the compatible underlying correction. Adopt its published patch for unreleased SJM 10.0.0 rather than inserting synthetic SMTP credentials into supplied Sessions. Existing public APIs, callback laziness, authentication failures, TLS settings and transport ownership remain unchanged.

This follows ADR 0015, ADR 0038 and ADR 0039. #421 introduced fixed-token OAuth; #692 added providers, and #698 owns the standalone batch integration. The separate stale credential-alias behavior after Session reuse is outside this correction.

Activity

  1. added this to the 10.0.0 milestone on Nov 5, 2026
  2. self-assigned this
    on Nov 5, 2026
  3. bbottema commented on Nov 5, 2026

    @bbottema
    OwnerAuthor
    Properties properties = new Properties();
    properties.setProperty("mail.transport.protocol", "smtps");
    properties.setProperty("mail.smtps.host", "smtp.example.org");
    properties.setProperty("mail.smtps.port", "465");
    properties.setProperty("mail.smtps.user", "current@example.org");
    properties.setProperty("mail.smtps.auth.mechanisms", "XOAUTH2");
    properties.setProperty("mail.smtps.ssl.checkserveridentity", "true");
    properties.setProperty("mail.smtp.user", "other@example.org");
    
    try (Mailer mailer = mail.mailerBuilder(Session.getInstance(properties))
            .withOAuth2AccessTokenProvider(accessTokens)
            .buildMailer()) {
        mailer.sync().sendMail(email);
    }

    Available on the codex/10.0.0 development branch with SMTP Connection Pool 4.4.1. Pooled OAuth connections now preserve the selected provider's username resolution, so an inactive SMTP username does not override the SMTPS account. Fixed tokens and callbacks retain normal username fallback and connection-time behavior without rewriting the original Session properties.

    Delivered in 6d328dd0, with aligned architecture and migration guidance and website examples.

    The correction follows ADR 0015, ADR 0038 and ADR 0039.

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