Skip to content

harshalkalewar/EmailService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📧 EmailService

A lightweight Spring Boot microservice that consumes email messages from a Kafka topic and sends them via SMTP. Ideal for building scalable, event-driven architectures with email capabilities.


🚀 Features

  • Kafka Consumer: Listens to the signup topic (or others).
  • SMTP Email Delivery: Sends emails with TLS/SSL encryption.
  • Environment-driven configuration: Externalize credentials via environment variables.
  • Simple & Focused: Single responsibility — email delivery.

🧩 Tech Stack

  • Java 17
  • Spring Boot
  • Spring for Kafka
  • Apache Kafka
  • JavaMail (SMTP)
  • Jackson (ObjectMapper)
  • Maven

📁 Project Structure

src/

├── main/

│ ├── java/com/example/emailservice/

│ │ ├── clients/

│ │ │ └── KafkaConsumerEmailClient.java # Kafka listener & email sender

│ │ ├── dtos/

│ │ │ └── EmailDto.java

│ │ └── utils/

│ │ └── EmailUtil.java

│ └── resources/

│ └── application.properties # Configurations


🛠️ Prerequisites

  1. Java 17+
  2. Kafka running (e.g., localhost:9092)
  3. SMTP server credentials (Gmail, Outlook, custom)
  4. Environment variables (or a .env file with dotenv support)

⚙️ Setup & Configuration

Place the real application.properties in src/main/resources/ or use a .env:

Properties

Kafka

spring.kafka.bootstrap-servers=localhost:9092

spring.kafka.consumer.group-id=emailService

SMTP (Injected via environment)

smtp.mail=smtp.gmail.com

smtp.port=587

email.username=${EMAIL_USERNAME}

email.password=${EMAIL_PASSWORD}


⚙️ Running the Service

1. Build the project

./mvnw clean install

2. Run the microservice

./mvnw spring-boot:run


🔧 Customize & Extend

  1. Add additional @KafkaListener(topic = "otherTopic", ...) methods for more email scenarios.

  2. Use @Header(KafkaHeaders.RECEIVED_TOPIC) to differentiate message types inside a listener.

  3. Add unit tests using JUnit & Mockito to validate consumer logic and error handling.


🧠 Troubleshooting

  1. "Could not resolve placeholder" errors → Ensure env vars or application.properties are correctly set.

  2. No connection to Kafka → Verify bootstrap-servers and that Kafka is running.

  3. Email authentication errors → Check SMTP settings and correct credentials.


Security Best Practices

  1. ❌ Never commit real credentials.

  2. ✅ Use environment variables or secret managers.

  3. ✅ Add application.properties and .env to .gitignore.


License & Author

Author: Harshal Kalewar

Project: EmailService

License: MIT

GitHub: @harshalkalewar


Contributions

Contributions and suggestions are welcome! Please open issues or PRs.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages