Can't connect with JavaMail even though Thunderbird works

G

Gary

I am trying to connect to our own mail server (Ubuntu, dovecot,
postfix) and, started by connecting to GMail as a test. I finally got
that to work and modified the code to work with our own server. Even
though Thunderbird connects regularly using port 993 with unencrypted
authentication, when i try to connect with JavaMail there is no
response from the server and the code just waits for return from the
store.connect method. As a test, I turned off firewalls at both client
and server ends which did not help. Here is the core of the code:

**********************
Properties props = new Properties();

session = Session.getDefaultInstance(props, null);

Store store = session.getStore("imap");

store.connect(serverName, 993, userName, password);
************************

If I try connecting with imaps, I get a "PKIX path building failed:"
exception since I have not imported the required certificate. But
using imaps should not be necessary because Thunderbird does
unencrypted authentication and does not have a certificate either, so
it seems like I should be able to get JavaMail to work without a
certificate the way Thunderbird works without a certificate. I am
really only interested in using JavaMail for authentication and not
actually reading email so if I can just make the original connection
and authenticate username and password, I don't really care about
anything beyond that - at least, not now.

Any advice or suggestions on how to proceed or what to look at would
be appreciated.

Thank you,
Gary Whitten
 
L

Lothar Kimmeringer

Gary said:
If I try connecting with imaps, I get a "PKIX path building failed:"
exception since I have not imported the required certificate. But
using imaps should not be necessary because Thunderbird does
unencrypted authentication and does not have a certificate either, so
it seems like I should be able to get JavaMail to work without a
certificate the way Thunderbird works without a certificate. I am
really only interested in using JavaMail for authentication and not
actually reading email so if I can just make the original connection
and authenticate username and password, I don't really care about
anything beyond that - at least, not now.

Any advice or suggestions on how to proceed or what to look at would
be appreciated.

To learn what is different, run Wireshark and compare the traces
you receive when connecting using Thunderbird and your program.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
N

Nigel Wade

I am trying to connect to our own mail server (Ubuntu, dovecot,
postfix) and, started by connecting to GMail as a test. I finally got
that to work and modified the code to work with our own server. Even
though Thunderbird connects regularly using port 993 with unencrypted
authentication,

I would be surprised if Thunderbird was attempting unencrypted
connections on port 993, or that your IMAP server was accepting them.
You would have to manually tweak a few things to get unencrypted IMAP on
port 993. The default would be SSL on that port as port 993 is defined
by IANA as the port for imaps, i.e. IMAP using SSL on connect. Are you
sure you are not referring to the Thunderbird option "Use secure
authentication", which is something else entirely. If SSL/TLS is
selected in the connection security drop-box then Thunderbird is using SSL.

If you want to use unencrypted IMAP the usual port is 143. That should
be the default in JavaMail if you don't specify the server port.
when i try to connect with JavaMail there is no
response from the server and the code just waits for return from the
store.connect method. As a test, I turned off firewalls at both client
and server ends which did not help. Here is the core of the code:

**********************
Properties props = new Properties();

session = Session.getDefaultInstance(props, null);

Store store = session.getStore("imap");

store.connect(serverName, 993, userName, password);
************************

If I try connecting with imaps, I get a "PKIX path building failed:"
exception since I have not imported the required certificate. But
using imaps should not be necessary because Thunderbird does
unencrypted authentication and does not have a certificate either, so
it seems like I should be able to get JavaMail to work without a
certificate the way Thunderbird works without a certificate.

The client only needs a cert. if the cert. used by the server is signed
by an unknown CA, usually due to using a self-signed cert. or defining
your own CA. In that case both Thunderbird and Java would require the CA
cert in order to verify the server cert. The server cert. is sent by the
server during the initial SSL handshake.
 
G

Gary

I would be surprised ifThunderbirdwas attempting unencrypted
connections on port 993, or that your IMAP server was accepting them.
You would have to manually tweak a few things to get unencrypted IMAP on
port 993. The default would be SSL on that port as port 993 is defined
by IANA as the port for imaps, i.e. IMAP using SSL onconnect. Are you
sure you are not referring to theThunderbirdoption "Use secure
authentication", which is something else entirely. If SSL/TLS is
selected in the connection security drop-box thenThunderbirdis using SSL.

If you want to use unencrypted IMAP the usual port is 143. That should
be the default inJavaMailif you don't specify the server port.









The client only needs a cert. if the cert. used by the server is signed
by an unknown CA, usually due to using a self-signed cert. or defining
your own CA. In that case bothThunderbirdand Java would require the CA
cert in order to verify the server cert. The server cert. is sent by the
server during the initial SSL handshake.

Thank you both for the replies.

Nigel, I think you have cleared up some confusion for me. Yes, you are
right, I WAS assuming that "Use secure authentication" meant that the
authentication was not using SSL (which I always thought was a little
weird). OK - so now I am down to working with the cert. although I
still don't understand the difference between how Thunderbird handles
the cert (I don't have to do anything) and how JavaMail handles is (I
do have to do something), but that is relatively minor. I think I have
what I need to get this working.

Thanks,
Gary
 
M

Martin Gregorie

I am trying to connect to our own mail server (Ubuntu, dovecot, postfix)
and, started by connecting to GMail as a test. I finally got that to
work and modified the code to work with our own server. Even though
Thunderbird connects regularly using port 993 with unencrypted
authentication, when i try to connect with JavaMail there is no response
from the server and the code just waits for return from the
store.connect method. As a test, I turned off firewalls at both client
and server ends which did not help. Here is the core of the code:
I'm using it to retrieve mail for POP3 from Dovecot and to deliver mail
to Postfix via SMTP with no problems at all. The Javamail client runs on
the same box as the mail system but is using hostname:port rather than
localhost to make the connection. Here is the guts of the code I use to
make the POP connection:

if (disableTOP)
props.setProperty("mail.pop3.disabletop", "true");

session = Session.getDefaultInstance(props);
messageSource = protocol + ":" + host + "," + user + "," +
password;
url = new URLName(messageSource);
store = session.getStore(url);
store.connect(host, user, password);
folder = store.getDefaultFolder();

Needless to say this has been stripped back to the bare essentials: in
the interests of emphasising the steps needed to get to the point where
messages can be read I've left out try/catch blocks and error handling.
I do not set any other POP-related properties.

I found out all I needed to know by reading the Javamail documents "API
design specification" and "API documentation" and using the example code
in the API design specification.
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top