2017-07-19 24 views
0

25,587個のポートとTLSを持つデフォルトのsmtpサーバーとして設定されているSMTPを使用してメールを送信しようとしています。 MS Exchange 2010.すべての認証データは正しいです。私はメールのWebインターフェイス経由でログインできるためです。以下のコードは、GmailのSMTPサーバとの作業を行いますが、私は私自身のSMTPサーバーを使用する場合には、証明書のパスとエラーに私をスロー:TLS SMTPメールJavaがSSLHandShakeExceptionをスローする

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:PKIXパス建物は失敗しました: sun.security.provider.certpath.SunCertPathBuilderException: にできないが、有効な証明書パスを見つける要求されたターゲットへ

public static void SendMailTLS(String to, String subject, String body) throws Exception{ 

    try { 
       java.util.Properties props = new java.util.Properties(); 
       props.put("mail.smtp.host", "sample"); 
       props.put("mail.smtp.port", "587"); 
       props.put("mail.smtp.starttls.enable", "true"); 
       props.put("mail.smtp.auth", "true"); 
       props.put("mail.smtp.connectiontimeout", "10000");  
       final String EmailUser = "sample"; 
       final String EmailPassword = "sample";  
       Session session = Session.getInstance(props, new javax.mail.Authenticator() { 
          protected PasswordAuthentication getPasswordAuthentication() { 
          return new PasswordAuthentication(
           EmailUser,EmailPassword); 
          } 
         }); session.setDebug(true);  
       InternetAddress fromAddress = new InternetAddress("sample", 
             "sample"); 
       InternetAddress toAddress = new InternetAddress("sample", 
             "sample"); 
       Message msg = new MimeMessage(session); 
       msg.setFrom(fromAddress); 
       msg.addRecipient(Message.RecipientType.TO,toAddress); 
       msg.setSubject(subject); 
       msg.setText(body);  
       Transport transport = session.getTransport("smtp"); 
       transport.connect(); 
       transport.sendMessage(msg, msg.getAllRecipients()); 
       } catch (MessagingException e) {e.printStackTrace();} 
    } 

私が何か間違ったことをやっていますか?

答えて

0

このエラーメッセージは、「sample」(MS Exchange 2010サーバー)という名前のサーバーが、Javaランタイムによって信頼されていない証明書を使用していることを示します。自己署名証明書を使用している可能性があります。したがって、この証明書をJava Runtime証明書ストアにインポートする必要があります(keytoolを使用)。

関連する問題