얼마전 인증을 해야하는 SMTP에 연결해야 했는데 그 방법 때문에 매우 고민했었습니다. Mail API에서 Authenticator는 제공을 하면서 ID와 PW를 설정하는 부분이 없어서 참 난감했었습니다. 영어 실력이 짧아서 관련 Document를 읽어보다가 못찾고 다만 API에 있는 Session 클래스의 getInstance(Properties prop, Authenticator auth) 메소드가 마음에 걸려 혹시나 하는 마음으로 만들어 봤었는데 잘 되더군요. sendmail 과 qmail 및 윈도기반 smtp server 몇 곳을 테스트 해봤는데 잘 되었습니다.
클래스 전체 소스는 다음과 같습니다.
/* * MyAuthenticator.java * 2002.05.27. * Hyunho Kim(falllove@ducc.or.kr) * * Copyrightⓒ 2002 FancyArts Corps. All rights reserved. */
/** * SMTP Authenticator */ public final class MyAuthenticator extends javax.mail.Authenticator {
댓글을 달아 주세요