Skip to content

MailerGenericBuilder.async() is ignored by testConnection() #615

Closed

Description

@bbottema

Problem

MailerGenericBuilder.async() is intended as a preconfigured default so callers do not need to pass async flags manually. That default applies to both sending mail and testing the SMTP connection.

Currently sendMail(email) honors the builder-level async default through operationalConfig.isAsync(), but testConnection() delegates directly to testConnection(false) and therefore always runs synchronously.

There is a second asymmetry in the explicit async path: sendMail(..., true) falls back to Simple Java Mail's built-in async handler when batch-module is not present, while testConnection(true) directly loads batch-module and fails when that optional module is absent.

Expected behavior

When a mailer is built with .async(), calling:

mailer.testConnection();

should behave like:

mailer.testConnection(true);

and return immediately while the connection test runs through the configured async execution path.

When batch-module is available, async connection testing can use it. When batch-module is absent, async connection testing should still work through the built-in async handler, matching the behavior of async sendMail(...).

Current behavior

mailer.testConnection() blocks because it hardcodes false, regardless of the builder-level async configuration.

mailer.testConnection(true) requires batch-module, even though async sending already has a built-in fallback.

Notes

This came up while triaging #608. The no-arg method blocking is valid for a normal synchronous mailer, but not for a mailer explicitly configured with .async().

Activity

  1. added this to the 8.13.0 milestone on Jul 3, 2026
  2. bbottema commented on Jul 3, 2026

    @bbottema
    OwnerAuthor

    Implemented.

    Summary:

    • MailerGenericBuilder.async() now applies to no-arg mailer.testConnection() through the configured async default.
    • testConnection(true) now mirrors async sendMail(...): it uses batch-module when available and falls back to the built-in async handler when that optional module is absent.

    Usage:

    Mailer mailer = MailerBuilder
        .withSMTPServer("smtp.example.com", 587, "user", "password")
        .async()
        .buildMailer();
    
    mailer.testConnection(); // returns immediately and runs asynchronously
  3. added a commit that references this issue on Jul 4, 2026
    800f294
  4. bbottema commented on Jul 8, 2026

    @bbottema
    OwnerAuthor

    Released in Simple Java Mail v9.0.0, which is now available from Maven Central:

    https://repo1.maven.org/maven2/org/simplejavamail/simple-java-mail/9.0.0/

    Release notes:
    https://github.com/bbottema/simple-java-mail/releases/tag/9.0.0

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

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions