Skip to content

Add typed API for SMTP EHLO/HELO client hostname #653

Closed

Description

@bbottema

Problem

Corporate SMTP relays sometimes expect the client to present a stable, recognizable hostname in the SMTP EHLO/HELO command. Even when the relay does not enforce this, a deliberate client hostname is useful for corporate logging, tracing, audit trails, and SMTP-side diagnostics because it makes application traffic recognizable in mail-server logs.

Angus Mail supports this through provider properties such as mail.smtp.localhost / mail.smtps.localhost, but Simple Java Mail currently only exposes this through raw withProperty(...) usage.

This is easy to miss and easy to confuse with withLocalBindAddress(...), which controls the local socket source address instead of the SMTP protocol identity.

Proposed API

Add a typed mailer-level setting, for example:

MailerBuilder
    .withSMTPServer("smtp.corp.example", 587, user, pass)
    .withSmtpClientHostname("orders-service.prod.example.com")
    .buildMailer();

Also consider a corresponding clearer/reset API:

clearSmtpClientHostname()

Property/config support could use a name such as:

simplejavamail.smtp.clienthostname=orders-service.prod.example.com

Implementation Notes

  • Map to the correct Angus/Jakarta Mail property for the active transport strategy:
    • mail.smtp.localhost
    • mail.smtps.localhost
  • Document this as the hostname sent in EHLO/HELO.
  • Position the use case as SMTP client identity for relay policy, logging, tracing, auditability, and diagnostics.
  • Explicitly distinguish it from local bind address and envelope sender.
  • Validate or document expected hostname/FQDN shape if appropriate, but avoid over-validating legitimate corporate hostnames.

Acceptance Criteria

  • A typed API sets the EHLO/HELO client hostname without requiring raw property usage.
  • The setting works for both SMTP and SMTPS transport strategies where applicable.
  • Existing raw withProperty(...) behavior remains available.
  • Documentation explains the corporate relay/logging/tracing use case and the difference from withLocalBindAddress(...).

Activity

  1. added this to the 9.1.0 milestone on Jul 11, 2026
  2. bbottema commented on Jul 11, 2026

    @bbottema
    OwnerAuthor

    Implemented in commit 57f9afd ( eat(smtp): add client hostname configuration).

  3. added a commit that references this issue on Jul 11, 2026
    57f9afd
  4. bbottema commented on Jul 11, 2026

    @bbottema
    OwnerAuthor

    Resolution note: implemented in 57f9afd (feat(smtp): add client hostname configuration).

    What changed:

    • Added typed mailer builder API for the SMTP EHLO/HELO client hostname.
    • Wired the value to the Jakarta Mail mail.smtp.localhost / mail.smtps.localhost properties via the active TransportStrategy.
    • Added property-backed configuration and Spring/Spring Boot mapping so config-file users get parity with the Java API.
    • Added tests covering config loading, session property mapping, Spring support and CLI mapping behavior.

    This supports both relay-policy setups and operational logging/tracing cases where the SMTP client identity needs to be stable and recognizable.

  5. bbottema commented on Jul 11, 2026

    @bbottema
    OwnerAuthor

    Released in Simple Java Mail 9.1.0: https://github.com/bbottema/simple-java-mail/releases/tag/9.1.0

    The SMTP client hostname API is available through the Java builder, property configuration and Spring configuration. The artifacts are available on Maven Central: https://repo1.maven.org/maven2/org/simplejavamail/simple-java-mail/9.1.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