Sun's Blog
Apache Common MailSender 본문
의존성 추가
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-email -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.5</version>
</dependency>
간단한 코드
SimpleEmail email = new SimpleEmail();
// setHostName에 실제 메일서버정보
email.setCharset("utf-8"); // 한글 인코딩
email.setSmtpPort(587);
email.setHostName("smtp.naver.com"); //SMTP서버 설정
email.setStartTLSEnabled(true);
try {
email.addTo("수신자@naver.com", "받는 사람"); // 수신자 추가
} catch (EmailException e) {
e.printStackTrace();
}
try {
email.setFrom("송신자@naver.com", "보내는 사람"); // 보내는 사람
email.setAuthenticator(new DefaultAuthenticator("아이디", "비밀번호"));
} catch (EmailException e) {
e.printStackTrace();
}
email.setSubject("Test message"); // 메일 제목
email.setContent("simple 메일 Test입니다", "text/plain; charset=utf-8");
try {
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
겪었던 오류
- setSSL 메서드가 deprecated 되어서 잠시 했었음. 대체로 setStartTLSEnabled 메서드가 생김
공식 홈페이지
https://commons.apache.org/proper/commons-email/userguide.html
Commons Email – Examples
A simple text email Our first example will create a basic email message to "John Doe" and send it through your Google Mail (GMail) account. Email email = new SimpleEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenti
commons.apache.org
'ETC' 카테고리의 다른 글
[10분 테코톡] 로이스의 Index (0) | 2023.08.07 |
---|---|
[10분 테코톡] 헙크의 자바 Reflectio (0) | 2023.08.06 |
JQuery 속성 조작, 객체 편집 메서드, 이벤트 등록 (0) | 2023.07.30 |
JQuery 속성 조작, 객체 편집 메서드, 이벤트 등록 (0) | 2023.07.29 |
[10분 테코톡] 폴로의 Forward proxy vs Reverse proxy vs Load Balancer (0) | 2023.07.23 |