diff --git a/README.md b/README.md
index 001bf80..2b18810 100644
--- a/README.md
+++ b/README.md
@@ -16,9 +16,9 @@
## Project Structure
- **src/main/java**: Contains Java source code.
-- `com.example.demo`: Main package containing application code.
+- `com.app`: Main package containing application code.
- **src/main/resources**: Contains application properties, static files, and templates.
-- `application.properties`: Configuration properties for the application.
+- `application.yml`: Configuration properties for the application.
- `static/`: Directory for static resources like CSS, JavaScript, etc.
- `templates/`: Directory for HTML templates.
- **src/test**: Contains test source code.
@@ -26,22 +26,20 @@
## Dependencies
- Spring Boot Starter Web: `spring-boot-starter-web`
+- Spring Boot Starter Mail: `spring-boot-starter-mail`
- Spring Boot Starter Test: `spring-boot-starter-test`
- [Add any additional dependencies here]
## API Documentation
-- [Link to API documentation if available]
+# Adding Email Service to Spring Boot Project
-## Contributing
-1. Fork the repository.
-2. Create a new branch: `git checkout -b feature/[feature_name]`
-3. Commit your changes: `git commit -am 'Add new feature'`
-4. Push to the branch: `git push origin feature/[feature_name]`
-5. Submit a pull request.
+## 1. Add Dependency
+Ensure that you have the necessary dependency in your `pom.xml` file to enable email functionality:
-## License
-[Specify the project's license, e.g., MIT License, Apache License]
+```xml
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
-## Authors
-[List project contributors and maintainers]
diff --git a/pom.xml b/pom.xml
index 2d8e109..6e2a902 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,10 @@
org.springframework.boot
spring-boot-starter-log4j2
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
org.springframework.boot
spring-boot-starter-test
diff --git a/src/main/java/com/app/controller/EmailController.java b/src/main/java/com/app/controller/EmailController.java
new file mode 100644
index 0000000..f981002
--- /dev/null
+++ b/src/main/java/com/app/controller/EmailController.java
@@ -0,0 +1,35 @@
+package com.app.controller;
+
+import jakarta.mail.MessagingException;
+import jakarta.mail.internet.MimeMessage;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessageHelper;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("email")
+public class EmailController {
+ private final JavaMailSender javaMailSender;
+ private static final String NO_REPLY_ADDRESS = "faiz.krm@yopmail.com";
+
+ EmailController(JavaMailSender javaMailSender) {
+ this.javaMailSender = javaMailSender;
+ }
+
+ @PostMapping
+ public ResponseEntity sendEmail(@RequestParam String[] to, @RequestParam String subject, @RequestParam String body) throws MessagingException {
+ MimeMessage message = javaMailSender.createMimeMessage();
+ MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8");
+ helper.setFrom(NO_REPLY_ADDRESS);
+ helper.setTo(to);
+ helper.setSubject(subject);
+ helper.setText(body);
+ javaMailSender.send(message);
+ return new ResponseEntity<>("Success", HttpStatus.OK);
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index a494062..5a0861d 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -3,6 +3,20 @@ spring:
active: local
application:
name: QuickStartSpringBoot
+ mail:
+ host: <>
+ port: <>
+ username: <>
+ password: <>
+ properties:
+ mail:
+ smtp:
+ starttls:
+ enable: true
+ auth: true
+ default-encoding: UTF-8
server:
port: 8080
+
+