# bbottema/simple-java-mail architecture

> Architecture diagram of the GitHub repository bbottema/simple-java-mail, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bbottema/simple-java-mail
- Repository: https://github.com/bbottema/simple-java-mail

## Overview

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: [`modules/simple-java-mail/src/main/java/org/simplejavamail/mailer`](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/mailer) (Mailer impl), [`modules/core-module/src/main/java/org/simplejavamail/api/internal`](https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/internal) (Shared internals), [`modules/simple-java-mail/src/main/java/org/simplejavamail/email`](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/email) (Builder API), [`modules/simple-java-mail/src/main/java/org/simplejavamail/converter`](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/converter) (Conversion pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Core API"]
  node_core_domain["Email model<br/>API domain"]
  node_core_mailer["Mailer contracts<br/>API mailer"]
  node_core_internal["Shared internals<br/>API internal"]
end

subgraph group_group_main["Main Runtime"]
  node_simple_builder["Builder API<br/>implementation"]
  node_simple_mailer["Mailer impl<br/>implementation"]
  node_simple_converter["Conversion pipeline<br/>implementation"]
  node_simple_loader["Module loader<br/>runtime support"]
end

subgraph group_group_optional["Optional Modules"]
  node_batch_module["Batch module<br/>optional extension"]
  node_socks_module["SOCKS module<br/>optional extension"]
  node_dkim_module["DKIM module<br/>optional extension"]
  node_smime_module["S/MIME module<br/>optional extension"]
  node_outlook_module["Outlook module<br/>optional extension"]
end

subgraph group_group_integration["Integration"]
  node_cli_module["CLI module<br/>integration"]
  node_spring_module["Spring module<br/>integration"]
end

subgraph group_group_support["Support"]
  node_core_tests["Test support"]
  node_simple_tests["Runtime tests<br/>support"]
  node_ci_release["Build & release<br/>support<br/>[.circleci]"]
end

node_core_domain -->|"builder API"| node_simple_builder
node_core_mailer -->|"mailer API"| node_simple_mailer
node_core_internal -->|"batch contracts"| node_batch_module
node_core_internal -->|"socks bridge"| node_socks_module
node_core_internal -->|"cli model"| node_cli_module
node_core_internal -->|"outlook model"| node_outlook_module
node_core_internal -->|"smime model"| node_smime_module
node_simple_builder -->|"creates"| node_core_domain
node_simple_builder -->|"hands off"| node_simple_mailer
node_simple_mailer -->|"detects modules"| node_simple_loader
node_simple_mailer -->|"send/ingest"| node_simple_converter
node_simple_mailer -->|"async send"| node_batch_module
node_simple_mailer -->|"proxy transport"| node_socks_module
node_simple_mailer -->|"sign mime"| node_dkim_module
node_simple_mailer -->|"secure mail"| node_smime_module
node_simple_converter -->|"parse msg"| node_outlook_module
node_simple_converter -->|"parse smime"| node_smime_module
node_spring_module -->|"configures"| node_core_mailer
node_cli_module -->|"drives builder"| node_simple_builder
node_core_tests -->|"test helpers"| node_simple_tests
node_ci_release -->|"verifies"| node_simple_tests

click node_core_domain "https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/email"
click node_core_mailer "https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/mailer"
click node_core_internal "https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/internal"
click node_simple_builder "https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/email"
click node_simple_mailer "https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/mailer"
click node_simple_converter "https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/converter"
click node_simple_loader "https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/internal/moduleloader"
click node_batch_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/batch-module/src/main/java/org/simplejavamail/internal/batchsupport"
click node_socks_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport"
click node_dkim_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/dkim-module/src/main/java/org/simplejavamail/internal/dkimsupport"
click node_smime_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/smime-module/src/main/java/org/simplejavamail/internal/smimesupport"
click node_outlook_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/outlook-module/src/main/java/org/simplejavamail/internal/outlooksupport"
click node_cli_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/cli-module/src/main/java/org/simplejavamail/internal/clisupport"
click node_spring_module "https://github.com/bbottema/simple-java-mail/tree/master/modules/spring-module/src/main/java/org/simplejavamail"
click node_core_tests "https://github.com/bbottema/simple-java-mail/tree/master/modules/core-test-module/src/main/java"
click node_simple_tests "https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/test/java"
click node_ci_release "https://github.com/bbottema/simple-java-mail/blob/master/.circleci"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core_domain,node_core_mailer,node_core_internal toneBlue
class node_simple_builder,node_simple_mailer,node_simple_converter,node_simple_loader toneAmber
class node_batch_module,node_socks_module,node_dkim_module,node_smime_module,node_outlook_module toneMint
class node_cli_module,node_spring_module toneRose
class node_core_tests,node_simple_tests,node_ci_release toneIndigo
```

## Components

### Core API

Public domain model, mailer contracts, shared config, and utility APIs.

- [Email model](https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/email): API domain · Public email, recipient, attachment, and builder contracts. · `modules/core-module/src/main/java/org/simplejavamail/api/email`
- [Mailer contracts](https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/mailer): API mailer · Mailer interfaces and config contracts used by implementations. · `modules/core-module/src/main/java/org/simplejavamail/api/mailer`
- [Shared internals](https://github.com/bbottema/simple-java-mail/tree/master/modules/core-module/src/main/java/org/simplejavamail/api/internal): API internal · 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](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/email): implementation · Concrete builder entry points for constructing emails and mailers. · `modules/simple-java-mail/src/main/java/org/simplejavamail/email`
- [Mailer impl](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/mailer): implementation · Concrete mailer, session setup, validation, and send orchestration. · `modules/simple-java-mail/src/main/java/org/simplejavamail/mailer`
- [Conversion pipeline](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/converter): implementation · Email, MimeMessage, .eml, and external format conversion subsystem. · `modules/simple-java-mail/src/main/java/org/simplejavamail/converter`
- [Module loader](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/main/java/org/simplejavamail/internal/moduleloader): runtime support · 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](https://github.com/bbottema/simple-java-mail/tree/master/modules/batch-module/src/main/java/org/simplejavamail/internal/batchsupport): optional extension · Async send and cluster-aware transport wrappers. · `modules/batch-module/src/main/java/org/simplejavamail/internal/batchsupport`
- [SOCKS module](https://github.com/bbottema/simple-java-mail/tree/master/modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport): optional extension · Authenticated SOCKS5 client/server bridge for SMTP transport. · `modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport`
- [DKIM module](https://github.com/bbottema/simple-java-mail/tree/master/modules/dkim-module/src/main/java/org/simplejavamail/internal/dkimsupport): optional extension · Signs outgoing MIME messages with DKIM before delivery. · `modules/dkim-module/src/main/java/org/simplejavamail/internal/dkimsupport`
- [S/MIME module](https://github.com/bbottema/simple-java-mail/tree/master/modules/smime-module/src/main/java/org/simplejavamail/internal/smimesupport): optional extension · S/MIME signing, encryption, recognition, and parsing support. · `modules/smime-module/src/main/java/org/simplejavamail/internal/smimesupport`
- [Outlook module](https://github.com/bbottema/simple-java-mail/tree/master/modules/outlook-module/src/main/java/org/simplejavamail/internal/outlooksupport): optional extension · 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](https://github.com/bbottema/simple-java-mail/tree/master/modules/cli-module/src/main/java/org/simplejavamail/internal/clisupport): integration · Picocli command-line layer over the builder API. · `modules/cli-module/src/main/java/org/simplejavamail/internal/clisupport`
- [Spring module](https://github.com/bbottema/simple-java-mail/tree/master/modules/spring-module/src/main/java/org/simplejavamail): integration · 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](https://github.com/bbottema/simple-java-mail/tree/master/modules/core-test-module/src/main/java): support · Shared test helpers and demo scaffolding for modules. · `modules/core-test-module/src/main/java`
- [Runtime tests](https://github.com/bbottema/simple-java-mail/tree/master/modules/simple-java-mail/src/test/java): support · Main module tests and demos covering build, send, and conversion flows. · `modules/simple-java-mail/src/test/java`
- [Build & release](https://github.com/bbottema/simple-java-mail/blob/master/.circleci): support · CI, coverage aggregation, release automation, and publishing support. · `.circleci`

## Connections

- 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.
