aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes IMAP/TLS Problem in connecting using java mail api. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "IMAP/TLS Problem in connecting using java mail api." Watch "IMAP/TLS Problem in connecting using java mail api." New topic
Author

IMAP/TLS Problem in connecting using java mail api.

P Chaudhari
Greenhorn

Joined: Mar 22, 2004
Posts: 22
Hi All,

I have a IMAP4 server running with TLS authentication switched on and have self signed certificate. I do not want to

install certificates so I tried DummySSLSocketFactory and DummyTrustManager provided by SUN but it gives following

error. Can anyone help me here?


DEBUG: setDebug: JavaMail version 1.3.3
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
javax.mail.MessagingException: Connection refused: connect;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:461)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at getmail.receiveEmails(getmail.java:40)
at getmail.main(getmail.java:18)



DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
javax.mail.MessagingException: Unconnected sockets not implemented;
nested exception is:
java.net.SocketException: Unconnected sockets not implemented
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at getmail.receiveEmails(getmail.java:27)


Here is my class.

import java.io.IOException;
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;
public class getmail {
// myauth auth;
public static void main(String args[]) throws Exception {
getmail getmail = new getmail();
getmail.receiveEmails();
}
private void receiveEmails() throws NoSuchProviderException, MessagingException, IOException {
// String host, name, passwd;
String host = "HOST";
String name = "USER";
String passwd = "PASSWORD";
java.security.Security.setProperty("ssl.SocketFactory.provider", "DummySSLSocketFactory");
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.imaps.socketFactory.fallback", "false");

Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Store store = session.getStore("imaps");
try {
store.connect(host, name, passwd); // exception here
System.out.println("store connected");
} catch (Exception e) {
// System.out.println("Error :" + e.toString());
e.printStackTrace();
System.exit(1);
}
}

Thanks in advance.

-Prasad
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39552
    
  27


You need to change this line to reflect the mail server you are using.

Note the error message: "java.net.ConnectException: Connection refused: connect", which has nothing to do with SSL, but seesm to point to a networking problem.


Ping & DNS - updated with new look and Ping home screen widget
P Chaudhari
Greenhorn

Joined: Mar 22, 2004
Posts: 22
Thanks for reply.

Inside my program I use correct host name, userid and password. This host is definitely reachable from my machine as I can ping it.

Any other clue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IMAP/TLS Problem in connecting using java mail api.
 
Similar Threads
sun.security.provider.certpath.SunCertPathBuilderException
SMTP(Simple Mail Transer Protocol)
javamail,No login methods supported exception
IMAP /TLS standalone programm works fine, in Tomcat fails.
Problem using Java Mail API