私のウェブサイトのメール認証機能を作成しようとしています。いくつかの問題。私は私のRequestedScoped
マネージドBeanからJavaEE + Glassfish3.1:Google Mailサーバーを使用してメールを送信するときに「例外:SMTPホストに接続できませんでした:smtp.gmail.com、ポート:465」
javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465; nested exception is: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
以下のコードがあるのです。これは、これは実際にはGlassfishの3.1のバグであるGlassfishの3.1 B25
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_PORT = "465";
private static final String emailSubjectTxt = "Email Confirmation";
private static final String emailFromAddress = "[email protected]";
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
@PostConstruct
public void init(){
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
}
public void sendEmailConfirmation() throws MessagingException{
boolean debug = true;
String sendTo = "[email protected]";
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");
//It dies at the next line
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myUserName", "myPassword");
}
});
session.setDebug(debug);
//Set the FROM address
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(emailFromAddress);
msg.setFrom(addressFrom);
//Set the TO address
InternetAddress[] addressTo = new InternetAddress[1];
addressTo[0] = new InternetAddress(sendTo);
msg.setRecipients(Message.RecipientType.TO, addressTo);
//Construct the content of the email confirmation
String message = "Test Content"
// Setting the Subject and Content Type
msg.setSubject(emailSubjectTxt);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
上で実行されます。ここでは、バグレポートは、私は、これはSSL関連の問題だと思う
http://java.net/jira/browse/GLASSFISH-15369
これはあなた自身またはサードパーティ製のホストサーバーで実行していますか? – BalusC
私自身は今のところです。しかし、最終的には第三者のホストされたサーバーを切り替える –
ああ、例外メッセージを変更しました。私のコメントの質問はもう意味をなさないでしょう。編集:それ以上のトレースにはありませんか?最後の原因は「エラー」について言及しています。 – BalusC