Secure and non secure email connections

V

verbal kint

Hi all,

I am currently working on a email reading program.
I have set up two different email accounts, one that requires a SSL
connection to the server, one that doesnot.

I have two properties file that I load depending on whether the email
account requires an SSL connection or not.

The SSL properties file looks like the following:
-------------------------------------------------------------------
mail.imap.port=993
mail.pop3.socketFactory.port=995
mail.imap.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.imap.socketFactory.port=993
mail.pop3.socketFactory.fallback=false
mail.imap.socketFactory.fallback=false
mail.pop3.port=995
mail.pop3.socketFactory.class=javax.net.ssl.SSLSocketFactory
-------------------------------------------------------------------

The non SSL properties file is empty

I execute the following code for each account:

Session session = Session.getDefaultInstance(props, null);
System.out.println(props.getProperty("mail.imap.socketFactory.class"));
Store store = session.getStore(serverType);
store.connect(server, username, password); // ----------- line that
causes the problem

When the first account is connecting, it is working regardless of
whether it is the SSL or non SSL account.
However the second one crashes.
If it is the SSL one, it just won't connect
If it is the non SSL one, I get the following error:
javax.mail.MessagingException:
sun.security.validator.ValidatorException: No trusted certificate
found;

I print the "mail.imap.socketFactory.class" property and I do get the
right property during the execution depending on the account.
I am very puzzled ... Any help will be greatly appreciated!
Thanks!
 
S

Sudsy

verbal kint wrote:
Session session = Session.getDefaultInstance(props, null);
I print the "mail.imap.socketFactory.class" property and I do get the
right property during the execution depending on the account.
I am very puzzled ... Any help will be greatly appreciated!
Thanks!

I seem to recall having some difficulties with this in the past.
So I pulled up the javadocs and found this in the getDefaultInstance
description:
"Since the default session is potentially available to all code
executing in the same Java virtual machine, ..."
Perhaps the correct way to approach the problem is to use getInstance
for each server. Store them in a container of your choice to facilitate
re-use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top