[Exception] javax.mail.AuthenticationFailedException
메일발송 시 아래와 같은 오류가 발생하였다.
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Authenticator auth = new MyAuthentication();
Session sess = Session.getInstance(props, auth);
..... 생략
Message msg = new MimeMessage(sess);
Transport.send(msg);
해결책.
MyAuthentication 에는 smtp host의 User ID 와 Password 가 들어 있다.
그것이 틀린 것입니다.
package common.util;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MyAuthentication extends Authenticator {
PasswordAuthentication pa;
public MyAuthentication() {
pa = new PasswordAuthentication("myid", "password");
}
public PasswordAuthentication getPasswordAuthentication() {
return pa;
}
}