How bbottema/simple-java-mail works
1. Repository shape
- This is a multi-module Maven library, not an application server.
- The main artifact is modules/simple-java-mail, with modules/core-module providing shared API contracts and several optional feature modules around it.
2. Core abstraction layer
- core-module defines the public domain model: Email, Recipient, attachment/resource types, mailer and builder interfaces, mailer configs, and internal feature interfaces.
- It also contains shared support contracts for optional capabilities such as batching, authenticated SOCKS, Outlook conversion, CLI, and S/MIME.
3. Primary message-building flow
- The usual flow is: builder API → Email model → validation/defaults/overrides → MimeMessage generation.
- The concrete implementation lives in simple-java-mail, where EmailBuilder, MailerBuilder, and internal builder classes assemble the message and apply configuration before transport.
4. Sending path
- simple-java-mail contains the concrete mailer implementation (MailerImpl) and session/transport helpers.
- It delegates actual SMTP delivery to the underlying Angus Mail / Jakarta Mail stack, while handling:
- connection/session configuration,
- authentication,
- timeouts,
- server identity checks,
- logging and result handling.
5. Batching and async delivery
- batch-module adds asynchronous sending and cluster-aware transport handling.
- It contributes lifecycle and transport wrappers plus concurrency utilities, letting the mailer send through pooled connections and manage cleanup separately from the core send path.
6. Authenticated SOCKS proxy support
- authenticated-socks-module provides a bridge around SOCKS5 authentication, including client helpers and a lightweight server-side proxy implementation.
- This module is used when SMTP traffic must pass through an authenticated SOCKS proxy that JavaMail itself cannot handle directly.
7. DKIM and S/MIME security extensions
- dkim-module signs outgoing mail with DKIM, operating on the MIME message before send.
- smime-module handles S/MIME signing/encryption and related parsing/modeling.
- These are intentionally separated so the core mailer can run without cryptographic dependencies unless those features are enabled.
8. Conversion subsystem
- simple-java-mail also contains the email conversion pipeline, converting between:
- Email
- MimeMessage
- .eml
- Outlook .msg
- This is a major architectural boundary: one path is for sending, another for ingesting/parsing external mail formats back into the internal model.
9. Outlook support
- outlook-module contains Outlook .msg parsing and proxy models.
- The parser extracts recipients, attachments, embedded content, and S/MIME-related metadata from Outlook messages, then feeds that into the shared conversion layer.
10. CLI module
- cli-module turns the builder API into a Picocli-based command-line interface.
- It maps builder methods to command definitions, provides value interpreters for files/certificates/enums/messages, and includes generated metadata/resources for help and runtime discovery.
11. Spring integration
- spring-module binds Simple Java Mail configuration to Spring / Spring Boot properties.
- Its role is configuration injection, not message processing: it feeds mailer and defaults/override settings into the core library.
12. Optional module loading boundary
- simple-java-mail includes a ModuleLoader and internal module markers to detect which optional modules are present.
- This keeps the main artifact usable in a minimal footprint while enabling features only when their module is on the classpath.
13. Shared utilities and validation
- The core and implementation modules share utilities for file handling, string conversion, preconditions, concurrency, and email validation.
- Validation is a first-class concern: address parsing, CRLF injection checks, completeness checks, and attachment/content encoding handling happen before send or conversion completes.
14. Tests, demos, and build infrastructure
- core-test-module supplies shared test helpers and demo scaffolding.
- simple-java-mail and cli-module include extensive unit/integration tests and sample apps, while CircleCI/Jacoco modules and release files support CI, coverage aggregation, and publishing.
Main entry points: mailer Mailer impl · internal Shared internals · email Builder API · converter Conversion pipeline
Components 17
Core API
Public domain model, mailer contracts, shared config, and utility APIs.
- Email model · Public email, recipient, attachment, and builder contracts.
modules/core-module/src/main/java/org/simplejavamail/api/email - Mailer contracts · Mailer interfaces and config contracts used by implementations.
modules/core-module/src/main/java/org/simplejavamail/api/mailer - Shared internals · Shared internal contracts for batching, SOCKS, CLI, Outlook, S/MIME, modules, and utilities.
modules/core-module/src/main/java/org/simplejavamail/api/internal
Main Runtime
Primary implementation for building, converting, and sending mail.
- Builder API · Concrete builder entry points for constructing emails and mailers.
modules/simple-java-mail/src/main/java/org/simplejavamail/email - Mailer impl · Concrete mailer, session setup, validation, and send orchestration.
modules/simple-java-mail/src/main/java/org/simplejavamail/mailer - Conversion pipeline · Email, MimeMessage, .eml, and external format conversion subsystem.
modules/simple-java-mail/src/main/java/org/simplejavamail/converter - Module loader · Detects optional modules and keeps the main artifact footprint minimal.
modules/simple-java-mail/src/main/java/org/simplejavamail/internal/moduleloader
Optional Modules
Classpath-enabled extensions for transport, security, and ingestion.
- Batch module · Async send and cluster-aware transport wrappers.
modules/batch-module/src/main/java/org/simplejavamail/internal/batchsupport - SOCKS module · Authenticated SOCKS5 client/server bridge for SMTP transport.
modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport - DKIM module · Signs outgoing MIME messages with DKIM before delivery.
modules/dkim-module/src/main/java/org/simplejavamail/internal/dkimsupport - S/MIME module · S/MIME signing, encryption, recognition, and parsing support.
modules/smime-module/src/main/java/org/simplejavamail/internal/smimesupport - Outlook module · Parses Outlook .msg content into proxy models for conversion.
modules/outlook-module/src/main/java/org/simplejavamail/internal/outlooksupport
Integration
Framework and command-line integration layers.
- CLI module · Picocli command-line layer over the builder API.
modules/cli-module/src/main/java/org/simplejavamail/internal/clisupport - Spring module · Spring and Spring Boot configuration binding for mail settings.
modules/spring-module/src/main/java/org/simplejavamail
Support
Tests, demos, and build/release infrastructure.
- Test support · Shared test helpers and demo scaffolding for modules.
modules/core-test-module/src/main/java - Runtime tests · Main module tests and demos covering build, send, and conversion flows.
modules/simple-java-mail/src/test/java - Build & release · CI, coverage aggregation, release automation, and publishing support.
.circleci
Connections 21
- Email model → Builder API: builder API · Builder implementations construct the public Email model from core contracts.
- Mailer contracts → Mailer impl: mailer API · Concrete mailer and builder classes implement the public mailer contracts.
- Shared internals → Batch module: batch contracts · Batch transport wraps the shared lifecycle/transport abstractions.
- Shared internals → SOCKS module: socks bridge · Authenticated SOCKS support extends the shared proxy bridge contracts.
- Shared internals → CLI module: cli model · CLI maps builder metadata and command models from shared internal contracts.
- Shared internals → Outlook module: outlook model · Outlook parsing uses shared proxy models and conversion-facing types.
- Shared internals → S/MIME module: smime model · S/MIME support shares parse and details models through the internal API boundary.
- Builder API → Email model: creates · Builder layer assembles emails and mailer configuration objects.
- Builder API → Mailer impl: hands off · Builder-produced configuration feeds the concrete mailer implementation.
- Mailer impl → Module loader: detects modules · Mailer runtime checks which optional features are available.
- Mailer impl → Conversion pipeline: send/ingest · Mailer shares the conversion boundary for MimeMessage creation and parsing.
- Mailer impl → Batch module: async send · Batch support can wrap the send path for pooled or clustered delivery.
- Mailer impl → SOCKS module: proxy transport · Mailer transport can be routed through authenticated SOCKS support.
- Mailer impl → DKIM module: sign mime · Outgoing MIME messages can be DKIM-signed before transport.
- Mailer impl → S/MIME module: secure mail · S/MIME can sign or encrypt mail as part of the message preparation flow.
- Conversion pipeline → Outlook module: parse msg · Conversion layer ingests Outlook messages through the Outlook parser.
- Conversion pipeline → S/MIME module: parse smime · Conversion layer cooperates with S/MIME parsing and metadata handling.
- Spring module → Mailer contracts: configures · Spring support injects configuration into mailer and defaults/overrides.
- CLI module → Builder API: drives builder · CLI exposes builder methods as Picocli commands and options.
- Test support → Runtime tests: test helpers · Shared test utilities support the main module's demos and integration tests.
- Build & release → Runtime tests: verifies · CI and release infrastructure run tests and coverage checks.