This README outlines the core concept of sending dynamic HTML emails in Java using a manual approach, with additional placeholders for exploring Thymeleaf and Freemarker as alternative methods. The structure reflects a modular setup allowing experimentation and future integration.
email-sender-java/
βββ pom.xml
βββ src/
β βββ main/
β βββ java/
β β βββ emailsender/
β β βββ manual/
β β βββ EnvLoader.java
β β βββ ManualEmailSender.java
β β βββ Main.java
β β βββ TemplateLoader.java
β βββ resources/
β βββ images/
β β βββ tatua-logo.png
β βββ templates/
β βββ welcome.html
β βββ newsletter.html
β βββ trial-expiry.html
βββ .env
Add to .env:
SENDER_EMAIL=youremail@example.com
SENDER_PASSWORD=yourpassword123How it works:
- Loads HTML template as raw string.
- Replaces placeholders like
{{name}}using.replace(). - Embeds inline images with Content-ID (CID).
Pros:
- Lightweight and easy to understand.
Cons:
- No support for loops or conditionals.
- Prone to manual errors with large templates.
Use case:
- Simple onboarding emails, static marketing messages.
Entry point: Main.java
How it works:
- Templates use
${variable}syntax orth:textattributes. - Rendered using
TemplateEngine.
Pros:
- Intuitive and integrates seamlessly with Spring Boot.
- Clean HTML templates with dynamic rendering.
Cons:
- Requires more setup (TemplateEngine, Context).
Use case:
- Spring-based applications, rich onboarding flows.
Entry point: To be implemented: ThymeleafMain.java
How it works:
- Templates written in
.ftlformat using${},#if,#list, etc. - Uses
ConfigurationandTemplateclasses to process variables.
Pros:
- Ideal for complex templating logic.
- Built-in support for loops, conditions, macros.
Cons:
- Slightly steeper learning curve.
Use case:
- Receipts, invoices, and dynamic reports.
Entry point: To be implemented: FreemarkerMain.java
| Use Case | Recommended |
|---|---|
| Static templates | Manual (for speed) |
| Spring Boot applications | Thymeleaf |
| Logic-heavy emails | Freemarker β |
For a scalable, reusable emailing service, Freemarker offers the most flexibility and structure.
This project offers a clean foundation for HTML email templating in Java. You can:
- Send styled emails with embedded images
- Swap templating engines easily
- Grow the project toward more advanced use cases (e.g., batch senders, queue-based systems)
Perfect for developers learning email automation or building custom notification systems.