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 |
Tags
- 최대공약수 예제
- 해외증권 양도세 한국투자증권
- javascript 자동완성
- tomcat log
- 피보나치함수
- 홈택스 해외주식 양도세
- katalon xpath
- js 자동완성
- 해외주식 양도세 신고
- 국세청 해외주식 양도세 신고방식
- katalon 비교
- 톰캣 실시간 로그
- 피보나치 예제
- katalon
- 재귀함수 예제
- recursion example
- bfs 미로탐색 java
- git 연동
- 테스트 자동화
- 한국투자증권 양도세 신고
- Katalon Recorder 사용법
- 피보나치함수 예제
- katalon 사용법
- java.sql.SQLSyntaxErrorException
- 재귀 예제
- katalon 자동화
- 한국투자증권 해외주식 양도세
- CSTS 폭포수 모델
- oracle group by
- 주식 양도세 신고방법
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' 카테고리의 다른 글
@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 |
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. (0) | 2024.04.28 |
스프링 부트의 자동 리소스 등록 (0) | 2024.04.24 |
Comments