헤르메스 LIFE

[Exception] javax.mail.AuthenticationFailedException 본문

Exception

[Exception] javax.mail.AuthenticationFailedException

헤르메스의날개 2014. 3. 4. 14:35
728x90

메일발송 시 아래와 같은 오류가 발생하였다.


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;

}

}


728x90