Skip to content
Snippets Groups Projects
Commit aedf37fd authored by Martin Gargalovič's avatar Martin Gargalovič
Browse files

mail-module impl

parent 821d3397
No related branches found
No related tags found
1 merge request!12Mail module
Pipeline #
...@@ -17,5 +17,12 @@ ...@@ -17,5 +17,12 @@
<properties> <properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip> <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties> </properties>
<dependencies>
<dependency>
<groupId>org.ifinalframework.annotation</groupId>
<artifactId>final-annotation-web</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
...@@ -27,6 +27,21 @@ ...@@ -27,6 +27,21 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </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> </dependencies>
<build> <build>
......
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;
}
}
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));
}
}
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;
}
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment