Solved

JavaMail with SSL

Posted on 2006-11-22
6
862 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
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.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 58
java jdbc batch example 8 41
Custom Java Application connects to database: Which one of the 20? 4 35
java mysql insert application 14 28
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

861 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