Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IMAP/TLS Problem in connecting using java mail api.

 
P Chaudhari
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
P Chaudhari
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic