Sto usando java mail per inviare email su smtp. Le impostazioni SMTP indicati di seguito:Java mail senza ssl - PKIX path building failed:
Properties props = new Properties();
Object put = props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.user", smtpUser);
props.put("mail.smtp.auth", true);
props.put("mail.debug", mailDebug);
props.put("mail.smtp.port", port);
Le credenziali SMTP sono stati verificati da telnet alla mia smtpHost con i dati riportati in alto. Tuttavia, ottengo la seguente eccezione quando utilizzo le impostazioni di cui sopra in java mail.
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
Nov 29, 2012 11:54:40 AM com.Test main
SEVERE: null
javax.mail.AuthenticationFailedException: 535 Incorrect authentication data
Quando aggiungo la linea:
props.put("mail.smtp.starttls.enable", false);
Esso genera di nuovo l'eccezione fallito stessa autenticazione.
se ho impostato mail.smtp.starttls.enable a vero, l'autenticazione ha esito positivo, ma ottengo la seguente eccezione:
220 TLS go ahead
Nov 28, 2012 5:32:36 PM com.Test main
SEVERE: null
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1918)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:652)
at javax.mail.Service.connect(Service.java:317)
Dopo aver attraversato vari thread del forum per quanto riguarda la seconda eccezione, Ho eseguito il programma InstallCert per recuperare il certificato autofirmato del server. Il InstallCert getta la seguente eccezione:
Opening connection to mydomain.com.au:443...
Starting SSL handshake...
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:542)
at sun.security.ssl.InputRecord.read(InputRecord.java:374)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:850)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1190)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1217)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1201)
at InstallCert.main(InstallCert.java:100)
Could not obtain server certificate chain
Così, sembra che il mio server non ha ssl, ma STARTTLS è abilitato. Quali sono i parametri corretti per l'invio della posta con STARTTLS attivo su un server senza SSL?
ho provato quello. Usato InstallCert come descritto nelle FAQ e ho ottenuto l'eccezione "javax.net.ssl.SSLException: messaggio SSL non riconosciuto, connessione in chiaro?". Sembra che il mio server non stia usando SSL. – janenz00
Ho modificato anche la mia domanda con l'eccezione InstallCert. – janenz00
Il problema con InstallCert è che funziona solo se si può fare una connessione SSL per cominciare. Se il tuo server supporta solo connessioni di testo normale convertite in connessioni SSL (TLS), InstalCert non sarà di aiuto. Potresti voler esaminare la classe [MailSSLSocketFactory] (http://javamail.kenai.com/nonav/javadocs/com/sun/mail/util/MailSSLSocketFactory.html), che ti consente di gestire più facilmente la firma automatica certificati che altrimenti non verrebbero verificati. –