Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » JavaMail failes on virgo
JavaMail failes on virgo [message #889979] Wed, 20 June 2012 13:08 Go to next message
jacob hameiri is currently offline jacob hameiriFriend
Messages: 13
Registered: June 2012
Junior Member
I am trying to send mail using JavaMail from a bundle, if I try the same code from a simple test jar ( not osgi ) on the same machine it succeeds.

this is my code:

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
		"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

Session session = Session.getInstance(props,
		new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(
						"user@gmail.com", "password");
			}
		});

try {

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress("user@gmail.com"));
	message.setRecipients(Message.RecipientType.TO,
			InternetAddress.parse("tomail@gmail.com"));
	message.setSubject("Testing 123");
	message.setText("test123");

	// create the message part
	MimeBodyPart messageBodyPart = new MimeBodyPart();

	// fill message
	messageBodyPart.setText("testing testing testing testing");

	Multipart multipart = new MimeMultipart("mixed");
	multipart.addBodyPart(messageBodyPart);

	// Part two is attachment
	messageBodyPart = new MimeBodyPart();
	DataSource source = new FileDataSource("/tmp/sample.pdf");
	messageBodyPart.setDataHandler(new DataHandler(source));

	messageBodyPart.setFileName("/tmp/sample.pdf");
	multipart.addBodyPart(messageBodyPart);

	// Put parts in message
	message.setContent(multipart);

	Transport.send(message);

	System.out.println("Done");

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


this is the exception:

        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 mailsender.test.SendMail(test.java:232) ~[mailsender-bundle-2.2.1.5.jar/:na]
        at mailsender.test.createReport(test.java:152) ~[mailsender-bundle-2.2.1.5.jar/:na]
        at mailsender.test.eventjob.execute(EventJob.java:100) [mailsender-bundle-2.2.1.5.jar/:na]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [com.springsource.org.quartz-1.6.2.jar:1.6.2]
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525) [com.springsource.org.quartz-1.6.2.jar:1.6.2]
Caused by: javax.mail.MessagingException: Exception reading response
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462) ~[na:na]
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260) ~[na:na]
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370) ~[na:na]
        at javax.mail.Service.connect(Service.java:297) ~[com.springsource.javax.mail-1.4.0.jar:1.4]
        at javax.mail.Service.connect(Service.java:156) ~[com.springsource.javax.mail-1.4.0.jar:1.4]
        at javax.mail.Service.connect(Service.java:105) ~[com.springsource.javax.mail-1.4.0.jar:1.4]
        at javax.mail.Transport.send0(Transport.java:168) ~[com.springsource.javax.mail-1.4.0.jar:1.4]
        at javax.mail.Transport.send(Transport.java:98) ~[com.springsource.javax.mail-1.4.0.jar:1.4]
        at mailsender.test.SendMail(test.java:227) ~[mailsender-bundle-2.2.1.5.jar/:na]
        ... 4 common frames omitted
Caused by: 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.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1731) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:925) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:785) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75) ~[na:1.6]
        at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97) ~[na:na]
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) ~[na:1.6.0_33]
        at java.io.BufferedInputStream.read(BufferedInputStream.java:237) ~[na:1.6.0_33]
        at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75) ~[na:na]
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440) ~[na:na]
        ... 12 common frames omitted
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323) ~[na:1.6.0_33]
        at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217) ~[na:1.6.0_33]
        at sun.security.validator.Validator.validate(Validator.java:218) ~[na:1.6.0_33]
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249) ~[na:1.6]
        at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185) ~[na:1.6]
        ... 24 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174) ~[na:1.6.0_33]
        at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238) ~[na:1.6.0_33]
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318) ~[na:1.6.0_33]
        ... 30 common frames omitted


any ideas ?

[Updated on: Wed, 20 June 2012 14:13]

Report message to a moderator

Re: JavaMail failes on virgo [message #892194 is a reply to message #889979] Wed, 27 June 2012 11:29 Go to previous message
Glyn Normington is currently offline Glyn NormingtonFriend
Messages: 1222
Registered: July 2009
Senior Member
Usually moving from conventional Java to OSGi is a matter of addressing class loading issues. We've seen some novelties in the area of security though, because of the way security is configured. I'm not sure what the problem is in this particular case. You might compare notes with this thread perhaps.
Previous Topic:Where to upload text file in virgo server
Next Topic:installing spring-security-cas-client-3.0.5.RELEASE.jar
Goto Forum:
  


Current Time: Thu Dec 18 19:44:41 GMT 2014

Powered by FUDForum. Page generated in 0.01844 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software