Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 한국투자증권 해외주식 양도세
- 주식 양도세 신고방법
- 피보나치함수
- oracle group by
- javascript 자동완성
- katalon xpath
- katalon
- 한국투자증권 양도세 신고
- 재귀함수 예제
- 테스트 자동화
- bfs 미로탐색 java
- 해외주식 양도세 신고
- 최대공약수 예제
- tomcat log
- CSTS 폭포수 모델
- 해외증권 양도세 한국투자증권
- recursion example
- katalon 비교
- java.sql.SQLSyntaxErrorException
- git 연동
- katalon 자동화
- 톰캣 실시간 로그
- katalon 사용법
- 국세청 해외주식 양도세 신고방식
- js 자동완성
- 재귀 예제
- Katalon Recorder 사용법
- 피보나치함수 예제
- 피보나치 예제
- 홈택스 해외주식 양도세
Archives
- Today
- Total
엄지월드
[Spring] 이메일 전송 구현(구글 이메일) 본문
구글 앱 비밀번호 추가

생성된 앱 비밀번호 확인

gradle.build
dependencies {
...
implementation 'org.springframework.boot:spring-boot-starter-mail'
...
}
application.properties
spring.mail.host=smtp.gmail.com # 이메일 gmail로 사용
spring.mail.port=587
spring.mail.username=your-email@naver.com
spring.mail.password=여기에_앱 비밀번호_입력
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
Controller
package com.travel.api.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.travel.api.service.EmailService;
@RestController
public class EmailController {
private final EmailService emailService;
@Autowired
public EmailController(EmailService emailService) {
this.emailService = emailService;
}
@GetMapping("/email/send")
public String sendEmail() {
emailService.sendEmail("to@naver.com", "테스트 이메일", "테스트 내용");
return "ok";
}
}
Service
package com.travel.api.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
@Service
public class EmailService {
private final JavaMailSender mailSender;
@Autowired
public EmailService(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public void sendEmail(String to, String subject, String body) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
}
}
API 호출 확인

발신자 이메일 주소로 접속 시, 발송된 것을 확인할 수 있음.

'java > Spring' 카테고리의 다른 글
| 지연 초기화 문제(Initializing Spring DispatcherServlet) (1) | 2025.06.30 |
|---|---|
| Spring Data JPA 메서드 명명 규칙 (0) | 2025.06.03 |
| @EnableConfigServer가 import 안되는 현상 (Spring Cloud BOM 적용) (0) | 2024.07.06 |
| Spring Boot JPA 실행 오류 (Error creating bean with name 'entityManagerFactory' defined in class path resource) (0) | 2024.05.04 |
| Spring Boot 버전 낮추는 방법(3 -> 2.7.5) (0) | 2024.05.01 |
Comments
