Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/#46-Mail' into feat/#44-Log…
Browse files Browse the repository at this point in the history
…in_springsecurity
  • Loading branch information
rlaalsghks8 committed Dec 21, 2024
2 parents 803753a + 35db0e3 commit 58a1c87
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server_9dokme/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
//jwt
implementation 'io.jsonwebtoken:jjwt:0.9.1'
//구글 이메일
implementation 'org.springframework.boot:spring-boot-starter-mail'



}
Expand Down
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 "전송 완료";
}
}
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;// 메일 내용
}
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);
}
}

0 comments on commit 58a1c87

Please sign in to comment.