Solved

JavaMail with SSL

Posted on 2006-11-22
6
858 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 49
javap bin 2 34
hibernate jars 4 30
Is Applet the way to go for my drag and drop system? 8 14
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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 …

773 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