Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,30 @@

## 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.
- **pom.xml**: Maven project configuration file.

## 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
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

## Authors
[List project contributors and maintainers]

4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/app/controller/EmailController.java
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}
14 changes: 14 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ spring:
active: local
application:
name: QuickStartSpringBoot
mail:
host: <<hostname>>
port: <<port>>
username: <<userName>>
password: <<password>>
properties:
mail:
smtp:
starttls:
enable: true
auth: true
default-encoding: UTF-8
server:
port: 8080