diff --git a/application/model/pom.xml b/application/model/pom.xml index aa4f9b9351f270657a187486488e3bb080640c10..705682e3f864cf36d89a1a6862990a51cb66cebb 100644 --- a/application/model/pom.xml +++ b/application/model/pom.xml @@ -17,5 +17,12 @@ <properties> <spring-boot.repackage.skip>true</spring-boot.repackage.skip> </properties> + <dependencies> + <dependency> + <groupId>org.ifinalframework.annotation</groupId> + <artifactId>final-annotation-web</artifactId> + <version>1.4.0</version> + </dependency> + </dependencies> </project> \ No newline at end of file diff --git a/application/module-mail/pom.xml b/application/module-mail/pom.xml index 4e729ff38d3890445b327bb0af9a73c66bd8d893..42f8c4f92758e6d03e79c87b1f9a9e378c06ac44 100644 --- a/application/module-mail/pom.xml +++ b/application/module-mail/pom.xml @@ -27,6 +27,21 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-mail</artifactId> + <version>3.0.4</version> + </dependency> + +<!-- <dependency>--> +<!-- <groupId>javax.mail</groupId>--> +<!-- <artifactId>mail</artifactId>--> +<!-- <version>1.4.7</version>--> +<!-- </dependency>--> </dependencies> <build> diff --git a/application/module-mail/src/main/java/org/fuseri/modulemail/service/EmailDto.java b/application/module-mail/src/main/java/org/fuseri/modulemail/service/EmailDto.java new file mode 100644 index 0000000000000000000000000000000000000000..7db3d98ab94b8707c99082794cae9922438e0d6c --- /dev/null +++ b/application/module-mail/src/main/java/org/fuseri/modulemail/service/EmailDto.java @@ -0,0 +1,15 @@ +package org.fuseri.modulemail.service; + +public class EmailDto { + + String sender; + String receiver; + String content; + + public EmailDto(String sender, String receiver, String content) { + this.sender = sender; + this.receiver = receiver; + this.content = content; + } + +} diff --git a/application/module-mail/src/main/java/org/fuseri/modulemail/service/MailControler.java b/application/module-mail/src/main/java/org/fuseri/modulemail/service/MailControler.java new file mode 100644 index 0000000000000000000000000000000000000000..87d7d61bd47b0cf0c9e3d7009adba12903e9ea30 --- /dev/null +++ b/application/module-mail/src/main/java/org/fuseri/modulemail/service/MailControler.java @@ -0,0 +1,28 @@ +package org.fuseri.modulemail.service; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/mail") +public class MailControler { + + private final MailService service; + + @Autowired + public MailControler(MailService service) { + this.service = service; + } + + @PostMapping() + public ResponseEntity sendMail(@RequestBody EmailDto emailDto) { + return ResponseEntity.ok(service.send(emailDto)); + } + + +} diff --git a/application/module-mail/src/main/java/org/fuseri/modulemail/service/MailService.java b/application/module-mail/src/main/java/org/fuseri/modulemail/service/MailService.java new file mode 100644 index 0000000000000000000000000000000000000000..32e13bc6ef3514b15632443ad6c0feb1780b51d2 --- /dev/null +++ b/application/module-mail/src/main/java/org/fuseri/modulemail/service/MailService.java @@ -0,0 +1,23 @@ +package org.fuseri.modulemail.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +@Service +public class MailService { + + @Autowired + private JavaMailSender emailSender; + + public String send(EmailDto dto) { + var message = new SimpleMailMessage(); + message.setFrom(dto.sender); + message.setTo(dto.receiver); + message.setSubject("Sprachschul"); + message.setText(dto.content); + + emailSender.send(message); + return "Success, you have sent: " + dto.content; + } +} diff --git a/application/module-mail/src/main/resources/application.properties b/application/module-mail/src/main/resources/application.properties index 8b137891791fe96927ad78e64b0aad7bded08bdc..fe4165e1b87c2710e2752688f06bb15eebaced0b 100644 --- a/application/module-mail/src/main/resources/application.properties +++ b/application/module-mail/src/main/resources/application.properties @@ -1 +1,8 @@ - +spring.mail.host=smtp.gmail.com +spring.mail.port=587 +# change the email to app dedicated mail +spring.mail.username=email@gmail.com +# set the mail app password for the dedicated email +spring.mail.password=password +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true