** 메일 계정 보안 설정 낮음으로 변경후 작업
1. build.gradle 추가
// mail
compile("org.springframework.boot:spring-boot-starter-mail")
compile "org.springframework:spring-context-support"
compile "com.sun.mail:javax.mail
2. application.yaml 추가
mail:
properties:
mail:
host: smtp.gmail.com
port: 587
username: id
password: pwd
smtp:
auth: true
connectiontimeout: 5000
timeout: 5000
writetimeout: 5000
starttls:
enable: true
socketFactory:
port: 465
class: javax.net.ssl.SSLSocketFactory
3. JavaMailSender 추가
@Bean
public static JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(587);
mailSender.setUsername("userEmail");
mailSender.setPassword("userPassword");
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
return mailSender;
}
4. sendMail 메소드 추가
public void sendMail() {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo("수신메일");
msg.setSubject("메일제목");
msg.setText("메일내용");
JavaMailSender javaMailSender = MailService.getJavaMailSender();
javaMailSender.send(msg);
}
'BackEND > Java' 카테고리의 다른 글
open jdk 1.8 버젼 다운로드 (0) | 2021.01.20 |
---|---|
java 설치 시 환경 변수 변경 및 확인 (0) | 2021.01.20 |
git ignore 적용하는 방법 (0) | 2021.01.20 |
war 배포시 윈도우 서버 서비스 등록하는 방법 (0) | 2021.01.20 |
md5, sha256 암호화 방법과 로그인 프로세스 (0) | 2020.12.11 |