Add email module: JavaMailSender on Spring Boot 4.1.2 / Jakarta Mail 2.1.5, tested against GreenMail with real transcripts

Nine tests, each writing a transcript to email/output/: the MIME tree for six message shapes (mixed > related >
alternative; addInline before setText puts the image first; addAttachment on a non-multipart helper throws),
Thymeleaf HTML and TEXT templates ([[...]] still HTML-escapes in TEXT mode, [(...)] does not), Devanagari subjects as
encoded-words and a wrong defaultEncoding turning them into '?', connections and latency through a delaying TCP proxy
(5 connections for one send per message, 1 for the varargs send, @Async returning in milliseconds), a void @Async
failure that never reaches the caller, a server that never sends the SMTP greeting blocking forever until
mail.smtp.timeout is set (connectiontimeout does not help), starttls.enable authenticating over plain text with the
base64 password captured on the wire while starttls.required refuses, spring.mail.* mapped onto JavaMailSenderImpl,
spring.mail.test-connection, and an email still sent when the transaction rolls back unless it waits for AFTER_COMMIT.

Found while writing: GreenMailExtension starts per test method by default, so a @DynamicPropertySource that reads its
port needs withPerMethodLifecycle(false).

No docs/ folder; the explanations live in the article's accordions.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7SK2mvUEELeLtMi1o
This commit is contained in:
Claude
2026-11-18 21:17:37 +05:30
parent c9a2b766bb
commit da700a564f
44 changed files with 1638 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Regenerates every file under output/.
#
# ./scripts/run-all.sh
#
# Needs JDK 25 and Maven 3.9. Nothing else: GreenMail runs inside the tests, and the "no mail host" failure comes
# from starting the packaged jar. Transcripts 01-09 come out of the test suite, so each line in them is an assertion
# that fails the build when it stops being true. Timings in 04 depend on the machine; ports in 06 change per run.
set -euo pipefail
cd "$(dirname "$0")/.."
mkdir -p output
echo "== test suite (transcripts 01-09)"
mvn -B test | tee /tmp/email-mvn.log | grep -E '^\[(INFO|WARNING|ERROR)\] Tests run:' | sed 's/^\[[A-Z]*\] //' > output/11-test-summary.txt
echo "== application without spring.mail.host (transcript 10)"
./scripts/no-mail-host.sh >/dev/null || true
echo
echo "output:"
ls -1 output