Skip to content

Expose SMTP connection creation-age expiration #743

Closed

Description

@bbottema

The smtp-connection-pool 4.2.0 release adds expiration based on a transport's total age. Expose that option through Simple Java Mail's Mailer configuration, standalone batch API, properties, Spring support, and generated CLI metadata.

With this you can control how long connections live, even if reused. This is useful for certain server that will auto-close connections after a certain period from the server side. With this new connection control, you can avoid having connections be cut off mid-flight.

Requirements:

  • Upgrade the runtime chain to smtp-connection-pool 4.2.0, clustered-object-pool 4.1.1, and generic-object-pool 2.5.1.
  • Treat creation-age expiration as optional Simple Java Mail configuration: it is disabled when no value is supplied, and any supplied duration must be positive. Do not expose smtp-connection-pool's 0 = disabled sentinel or use Integer.MAX_VALUE as a disabled value.
  • Provide explicit clear methods for removing a configured creation-age threshold.
  • A missing per-cluster value inherits the global value; a positive per-cluster value overrides it. There is no separate per-cluster sentinel for disabling a positive global value.
  • Preserve the existing idle-expiration convention and behavior. When idle-age and creation-age expiration are both configured, either condition can make an available connection eligible for retirement. Handle neither, idle-only, creation-only, and combined configurations explicitly using the upstream expiration policies.
  • Expiration is asynchronous and applies while connections are available. It must not interrupt active leases, claiming or releasing must not reset creation age, and the option must be documented as an eligibility threshold rather than a strict lifetime guarantee.
  • Include the value in immutable configuration copying, equality, hash codes, settings identity, and the existing first-registration cluster configuration behavior.
  • Simple Java Mail uses smtp-connection-pool's direct API, not its Jakarta provider property. Keep one component in charge of pooling and do not wrap the smtppool provider.
  • Add focused regression coverage for defaults, positive-value validation, clearing, global and cluster property parsing, cluster inheritance and override, all expiration-policy combinations, Spring propagation, generated CLI options, and the upstream fix that closes a transport after failed connection preparation, preserves a secondary close failure, and never reuses the failed transport.
  • Do not expose the new upstream cancellation, total-budget claim, or transport-abort APIs in this patch.
  • Update the API usage documentation and release notes with a clear configuration example and the asynchronous-retirement caveat.

Activity

  1. added this to the 9.3.5 milestone on Sep 18, 2026
  2. self-assigned this
    on Sep 18, 2026
  3. bbottema commented on Sep 18, 2026

    @bbottema
    OwnerAuthor

    Released in 9.3.5. This is useful when an SMTP server imposes its own maximum connection lifetime: configure a shorter pool lifetime so available connections are retired before the server is likely to cut them off.

    Java API:

    Mailer mailer = MailerBuilder
            .withSMTPServer("smtp.example.com", 587, "user", "password")
            .withConnectionPoolExpireAfterCreationMillis(900_000) // 15 minutes
            .buildMailer();

    Equivalent property:

    simplejavamail.defaults.connectionpool.expireaftercreation.millis=900000

    The value must be positive. Leave it unset, or call clearConnectionPoolExpireAfterCreationMillis(), to keep creation-age expiration disabled. Retirement is asynchronous and only applies while a connection is available; it does not interrupt an active send. See the Mailer configuration and pooling guide for the complete API, batch, property, Spring, and per-cluster examples.

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

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions