Results 1 to 6 of 6
  1. #1
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Thumbs up Error in sending mail using ssl server

    Hi All

    Please help in resolving the below issue i am getting the following error while sending mail. I am using the IMAP server and it is ssl configured

    Java Code:
    DEBUG: setDebug: JavaMail version 1.4ea
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "mail.test.com", port 465, isSSL true
    DEBUG SMTP: exception reading response: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed
    javax.mail.MessagingException: Exception reading response;
      nested exception is:
    	javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed
    	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
    	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
    	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    	at javax.mail.Service.connect(Service.java:275)
    	at com.test.test.JavaMailApp2.main(JavaMailApp2.java:59)
    Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed
    	at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
    	at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
    	at java.io.BufferedInputStream.fill(Unknown Source)
    	at java.io.BufferedInputStream.read(Unknown Source)
    	at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
    	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
    	... 4 more
    Caused by: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed
    	at sun.security.validator.PKIXValidator.doValidate(Unknown Source)
    	at sun.security.validator.PKIXValidator.doValidate(Unknown Source)
    	at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
    	at sun.security.validator.Validator.validate(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    	... 17 more
    Caused by: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed
    	at sun.security.provider.certpath.PKIXMasterCertPathValidator.validate(Unknown Source)
    	at sun.security.provider.certpath.PKIXCertPathValidator.doValidate(Unknown Source)
    	at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(Unknown Source)
    	at java.security.cert.CertPathValidator.validate(Unknown Source)
    	... 24 more
    Below is the source code of the program.

    Java Code:
    package com.test.test;
    
    import java.security.Security;
    import java.util.Properties;
    
    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.NoSuchProviderException;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    
    public class JavaMailApp {
    	
    	
    	public static void main( String[] args )
        {	
    
    		String d_email = "ots.support@test.com";
    		String d_uname = "ots.support";
    		String d_password = "password";
    		String d_host = "mail.test.com";
    		String d_port  = "465"; //465,587
    		String m_to = "user1@test.com";
    		String m_subject = "Testing";
    		String m_text = "Hey, this is the testing email.";
    		
    		Properties props = new Properties();
    		props.put("mail.smtp.user", d_email);
    		props.put("mail.smtp.host", d_host);
    		props.put("mail.smtp.port", d_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", d_port);
    		props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    		props.put("mail.smtp.socketFactory.fallback", "false");
    		
    		SMTPAuthenticator auth = new SMTPAuthenticator();
    		Session session = Session.getInstance(props, auth);
    		session.setDebug(true);
    		
    		MimeMessage msg = new MimeMessage(session);
    		try {
    			msg.setText(m_text);
    			msg.setSubject(m_subject);
    			msg.setFrom(new InternetAddress(d_email));
    			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
    			
    			Transport transport = session.getTransport("smtps");
    			transport.connect(d_host, 465, d_uname, d_password);
    			transport.sendMessage(msg, msg.getAllRecipients());
    			transport.close();
    		} catch (MessagingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
        }
    }
    
    public class SMTPAuthenticator extends Authenticator{
    	public PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication("ots.support@test.com", "password");
        }
    }
    I have also added the certificate to my keystore using the following command and still i am facing this issue.

    keytool -import -trustcacerts -alias root -file mail_test_com.crt -keystore keystore.jks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    More like the validation is failed.

    Check all the certificate using the command,

    keytool -list -keystore $JAVA_HOME/lib/security/cacerts -v

  3. #3
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    Thanks a lot Eranga for your help i am getting the following error while executing the command
    Java Code:
    C:\Program Files\Java\jdk1.6.0_13\bin>keytool -list -keystore "C:\Program Files\
    Java\jre6\lib\security\cacerts" -v
    Enter keystore password:
    keytool error: java.io.IOException: Keystore was tampered with, or password was
    incorrect
    java.io.IOException: Keystore was tampered with, or password was incorrect
            at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:771)
            at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:3
    8)
            at java.security.KeyStore.load(KeyStore.java:1185)
            at sun.security.tools.KeyTool.doCommands(KeyTool.java:715)
            at sun.security.tools.KeyTool.run(KeyTool.java:172)
            at sun.security.tools.KeyTool.main(KeyTool.java:166)
    Caused by: java.security.UnrecoverableKeyException: Password verification failed
    
            at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:769)
            ... 5 more
    I have given the correct password only.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    This can cause another issue. In SSL the password define in keystorePass element. That tag must be in Factory tag. Check it.

  6. #6
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    I have entered the same password as the keystore password. What is the Factory Tag you mentioned.

Similar Threads

  1. Replies: 3
    Last Post: 04-05-2010, 02:19 AM
  2. problem with sending mail usin javaX.mail api
    By sandeepsai39 in forum New To Java
    Replies: 4
    Last Post: 11-25-2009, 05:37 AM
  3. Sending a Mail
    By haiforhussain in forum Advanced Java
    Replies: 7
    Last Post: 07-30-2008, 12:28 AM
  4. Sending Mail Using Sockets
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:05 PM
  5. Sending a mail with the local mail program
    By thedude in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2007, 12:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •