Solved

JavaMail with SSL

Posted on 2006-11-22
6
851 Views
Last Modified: 2013-11-24
Hi,

I have a problem checking a mailbox using JavaMail API with SSL. The mail server accepts only SSL connections.

Here is the fragment of code:

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());            
Security.setProperty("ssl.SocketFactory.provider", "DummySSLSocketFactory");
            
Properties props = new Properties();
props.setProperty("mail.imap.port", "993");
props.setProperty("mail.imap.socketFactory.port", "993");

Session session = Session.getInstance(props, null);
Store store = session.getStore("imap");

store.connect(host, username, password);

When coming to the last line, the application (FastMail) is waiting for a minute and then throws a message:

javax.mail.MessagingException: ;
  nested exception is:
      java.io.IOException
      at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:441)
      at javax.mail.Service.connect(Service.java:233)
      at javax.mail.Service.connect(Service.java:134)
      at fastmail.FastMail.getMessages(FastMail.java:33)
      at fastmail.FastMail.main(FastMail.java:62)

Could you help me to debug this problem?
0
Comment
Question by:pamir
  • 4
  • 2
6 Comments
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 250 total points
ID: 17994628
add this property as well

props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
0
 

Author Comment

by:pamir
ID: 17994967
OK added, but the result is almost the same - the application hangs up without any message at

store.connect(host, username, password);
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17995039
> props.setProperty("mail.smtp.socketFactory.class",
> "javax.net.ssl.SSLSocketFactory");

sorry about typo, this should be

props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:pamir
ID: 17995196
Yes, I have already corrected the typo - the result is as I have stated above.
0
 

Author Comment

by:pamir
ID: 17996659
Oops, I have found the error! The full path to the class DummySSLSocketFactory should be pointed, including the package.

So instead of "DummySSLSocketFactory" I have put "fastmail.DummySSLSocketFactory" and everything works!
0
 

Author Comment

by:pamir
ID: 17996716
Thanks Ajay-Singh, I am giving you the points anyway since you have directed me to the right direction.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changePi Challenge 15 75
countPairs challenge 7 58
wordmultiple challenge 12 89
GUI builder for Eclipse? 8 8
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now