티스토리 뷰

Skill/spring

SMTPConfig.java

진열사랑 2025. 1. 13. 10:37

@Data
@Configuration
@ConfigurationProperties(prefix="smtp")
public class SMTPConfig {
private String host;
private String port;
private Boolean auth;
private Boolean startTLSEnable;
private String user;
private String password;

/**--------------------------------------------------------------------
* ■서비스 등록
--------------------------------------------------------------------**/
@Bean
public JavaMailSender getMailSender() {
JavaMailSenderImpl objJavaMailSenderImpl = new JavaMailSenderImpl();

objJavaMailSenderImpl.setJavaMailProperties(getMailProperties());

// 인증 계정이 있는 경우
if(auth) {
objJavaMailSenderImpl.setUsername(user);
objJavaMailSenderImpl.setPassword(password);

Session session = Session.getInstance(getMailProperties(), new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
session.setDebug(true);
}

return objJavaMailSenderImpl;
}

/**--------------------------------------------------------------------
* ■SMTP 프로퍼티 설정
--------------------------------------------------------------------**/
private Properties getMailProperties() {
Properties properties = new Properties();

properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.smtp.starttls.enable", startTLSEnable ? "true" : "false");
properties.setProperty("mail.smtp.ssl.trust", host);
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.auth", auth ? "true" : "false");
properties.setProperty("mail.smtp.port", port);
properties.setProperty("mail.smtp.socketFactory.port", port);
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

return properties;
}
}

'Skill > spring' 카테고리의 다른 글

Query Timeout 적용 최종  (0) 2025.01.13
ServiceInitializer.java  (0) 2025.01.13
ServiceInit.java  (0) 2025.01.13
ServiceConfig.java  (0) 2025.01.13
ServiceAOP.java  (0) 2025.01.13
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
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
글 보관함