-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat/#46-Mail' into feat/#44-Log…
…in_springsecurity
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
server_9dokme/src/main/java/com/example/server_9dokme/member/controller/EmailController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.server_9dokme.member.controller; | ||
|
||
import com.example.server_9dokme.member.dto.request.MailDto; | ||
import com.example.server_9dokme.member.service.EmailService; | ||
import jakarta.validation.Valid; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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 | ||
@Slf4j | ||
@RequestMapping("/api") | ||
public class EmailController { | ||
@Autowired | ||
private EmailService emailService; | ||
@PostMapping("/mail") | ||
public String execMail(@RequestBody @Valid MailDto dto) { | ||
|
||
emailService.sendSimpleMessage(dto); | ||
return "전송 완료"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
server_9dokme/src/main/java/com/example/server_9dokme/member/dto/request/MailDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.server_9dokme.member.dto.request; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class MailDto { | ||
private String emailAddr; // 수신 이메일 | ||
private String emailTitle; // 메일 제목 | ||
private String emailContent;// 메일 내용 | ||
} |
29 changes: 29 additions & 0 deletions
29
server_9dokme/src/main/java/com/example/server_9dokme/member/service/EmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.server_9dokme.member.service; | ||
|
||
import com.example.server_9dokme.member.dto.request.MailDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class EmailService { | ||
|
||
@Value("${google.email}") | ||
private String FROM_ADDRESS; | ||
@Autowired | ||
private JavaMailSender emailSender; | ||
public void sendSimpleMessage(MailDto mailDto) { | ||
SimpleMailMessage message = new SimpleMailMessage(); | ||
message.setFrom(FROM_ADDRESS); | ||
message.setTo(mailDto.getEmailAddr()); | ||
message.setSubject(mailDto.getEmailTitle()); | ||
message.setText(mailDto.getEmailContent()); | ||
emailSender.send(message); | ||
} | ||
} |