Solved

JavaMail with SSL

Posted on 2006-11-22
6
855 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

932 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

10 Experts available now in Live!

Get 1:1 Help Now