2011-03-08 3 views
3

는 내가 EJB를 ussing 이메일을 보내려고하지만 난 유일한 것은 내가이 예외의 대가로 얻을 :은 (자바 EE-6)

java.lang.RuntimeException: javax.mail.AuthenticationFailedException: failed to connect, no password specified? 

이 얼마나 내 EJB 다음과 같습니다

@Stateless(name = "ejbs/EmailServiceEJB") 
public class EmailServiceEJB extends Authenticator implements IEmailServiceEJB { 

public PasswordAuthentication getPasswordAuthentication() { 
    return new PasswordAuthentication("[email protected]", 
      "xxxxxxx"); 
} 

public void sendAccountActivationLinkToBuyer(String destinationEmail, 
     String name) { 
    // OUR EMAIL SETTINGS 
    String host = "smtp.gmail.com";// Gmail 
    int port = 465; 
    String serviceUsername = "[email protected]"; 
    String servicePassword = "xxxxxxx";// Our Gmail password 

    Properties props = new Properties(); 
    props.put("mail.smtp.user", serviceUsername); 
    props.put("mail.smtp.host", host); 
    props.put("mail.smtp.port", port); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.debug", "true"); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.socketFactory.port", port); 
    props.put("mail.smtp.socketFactory.class", 
      "javax.net.ssl.SSLSocketFactory"); 
    props.put("mail.smtp.socketFactory.fallback", "false"); 

    // Destination of the email 
    String to = destinationEmail; 
    String from = "[email protected]"; 

    // Creating a javax.Session with the our properties 
    Session session = Session.getInstance(props); 

    try { 
     Message message = new MimeMessage(session); 
     // From: is our service 
     message.setFrom(new InternetAddress(from)); 
     // To: destination given 
     message.setRecipients(Message.RecipientType.TO, 
       InternetAddress.parse(to)); 
     message.setSubject("Comfirm your account"); 
     // Instead of simple text, a .html template should be added here! 
     message.setText("Welcome....... "); 

     Transport transport = session.getTransport("smtp"); 
     transport.connect(host, port, serviceUsername, servicePassword); 
     Transport.send(message, message.getAllRecipients()); 
     transport.close(); 

    } catch (MessagingException e) { 
     throw new RuntimeException(e); 
    } 

} 

}는 암호가 지정되지 않은 것을 말하는 계속 내가 왜 해달라고

알고? SSLSocketFactory와 관련이 있습니까? 어딘가에서 getPasswordAuthenticion() 메서드를 호출해야합니까, 아니면 내 관리 빈에서 두 번째 메서드를 호출하면 필요한 것입니까?

+0

GlassFish와 같은 응용 프로그램 서버를 사용하고 있습니까? – musiKk

+0

예 글래스 피시 3.0 – sfrj

답변

8

는 모르겠지만, 당신이보고 싶을 수 있습니다

http://spitballer.blogspot.com/2010/02/sending-email-via-glassfish-v3.html

그것은 자바 EE, 이메일을 구성하는 다른 방법을 보여주는 나는 일이 훨씬 나아 졌다고 생각한다. 연결 세부 정보는 컨테이너 관리 데이터베이스 연결과 마찬가지로 컨테이너 수준에서 구성됩니다.

+1

두 번째. 그것이 응용 프로그램 서버에 대해 물었을 때 염두에 두었던 것입니다. 이것은 확실히가는 길입니다. – musiKk

+0

이것은 대단한 답변이었습니다 :) 이제 10 분만에 내 앱이 전자 메일을 보내고 Gmail 계정을 사용하고 있습니다. 와우는 얼마나 쉽게 놀랐는지 :) 나는 유리주를 좋아합니다. 안녕하세요. – sfrj

1

SPF와 DKIM을 읽으십시오.

코드가 필요한 정보의 1/2에 불과하기 때문에 무엇이 잘못되었는지 알기가 어렵습니다. 실제 문제는 코드가 사용자의 환경에 맞지 않는 것일 수 있으며 SPF와 DKIM이 공용 SMTP 서버에 연결하고 전자 메일을 보내는 것이 작동하지 않는 경우가 종종 있습니다.

적어도 SPF와 DKIM에 대해 조금 읽은 후에는 문제가 아닌지 또는 문제가 아닌지를 알 수 있습니다. 코드가 작동하지 않는 이유