java mail - SSL POP3

Dear all,

Would you please help to solove the problem? In the code, my flow wen to the else case

I tried to connecton to Exchange server.

When I try to telnet the 995,

$ telnet <mail server IP adddress> 995

Trying <mail server IP adddress> ...

telnet: Unable to connect to remote host: Connection refused

It seems the connection to 995 is OK.

29.05.2007 14:57:07:585 SendMailAgent: Exception receive()

javax.mail.MessagingException: Connect failed;

nested exception is:

java.net.ConnectException: Connection refused

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)

at javax.mail.Service.connect(Service.java:275)

at javax.mail.Service.connect(Service.java:156)

at SendMailAgent.receive(SendMailAgent.java:331)

at BBPollingEngine.run(BBPollingEngine.java:42)

at java.util.TimerThread.mainLoop(Timer.java:432)

at java.util.TimerThread.run(Timer.java:382)

Caused by: java.net.ConnectException: Connection refused

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)

at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)

at java.net.Socket.connect(Socket.java:452)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(DashoA12275)

at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(DashoA12275)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:163)

at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)

at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)

... 6 more

/**

* fetch messages and process them.

*/

public void receive()

{

Store store=null;

Folder folder=null;

String popServer = this.pop;

String popUser = this.pop_user;

String popPassword = this.pop_password;

String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

Session session = null;

Properties props = null, pop3Props = null;

try

{

if (pop3_flag.equals("0"))

{

//Get hold of the default session

props = System.getProperties();

session = Session.getDefaultInstance(props, null);

//Get hold of a POP3 message store, and connect to it

store = session.getStore("pop3");

store.connect(popServer, popUser, popPassword);

logac.info(this.getClass().getName() + ": store.connect("+popServer+","+popUser+")");

//logac.info(this.getClass().getName() + ": store.connect("+popServer+","+popUser+")");

}

else

{

props = System.getProperties();

props.setProperty( "mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

props.setProperty( "mail.pop3.socketFactory.fallback", "false");

props.setProperty("mail.pop3.port", "995");

props.setProperty("mail.pop3.socketFactory.port", "995");

session = Session.getInstance(props);

store = session.getStore("pop3");

store.connect(popServer, popUser, popPassword);

logac.info(this.getClass().getName() + ": store.connect("+popServer+","+popUser+")");

/**

//pop3Props = new Properties();

pop3Props = System.getProperties();

pop3Props.setProperty("mail.pop3.socketFactory.class", "DummySSLSocketFactory");

pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");

//pop3Props.setProperty("mail.pop3.port", "995");

//pop3Props.setProperty("mail.pop3.socketFactory.port", "995");

URLName url = new URLName("pop3", popServer, 995, "", popUser, popPassword);

session = Session.getInstance(pop3Props, null);

session.setDebug(true);

store = new POP3SSLStore(session, url);

logac.info(this.getClass().getName() + ": before store.connect");

store.connect();

//store.connect(popServer, popUser, popPassword);

logac.info(this.getClass().getName() + ": store.connect("+popServer+","+popUser+")");

**/

}

//Try to get hold of the default folder

folder = store.getDefaultFolder();

if (folder == null)

{

logac.info(this.getClass().getName()+": No default folder");

throw new Exception("No default folder");

}

//and its INBOX

folder = folder.getFolder("INBOX");

if (folder == null)

{

logac.info(this.getClass().getName()+": No POP3 INBOX");

throw new Exception(this.getClass().getName() + ": No POP3 INBOX");

}

//Open the folder for read only

//folder.open(Folder.READ_ONLY);

//READ and WRITE allowed

folder.open(Folder.READ_WRITE);

//Get the message wrappers and process them

Message[] msgs = folder.getMessages();

logac.info(this.getClass().getName() + ": msgNum:"+msgs.length);

String msisdn = null, default_email = null, service_type = null;

for (int msgNum = 0; msgNum < msgs.length; msgNum++)

{

printMessage(msgs[msgNum]);

msgs[msgNum].setFlag(Flags.Flag.DELETED, true); // set the DELETED flag

}

}

catch (Exception ex)

{

loger.error(this.getClass().getName() + ": Exception receive()", ex);

}

finally

{

//Close down

try

{

if (folder!=null)

folder.close(true);//clear all DELETED message from folder

if (store!=null)

store.close();

}

catch (Exception ex2)

{

loger.error(this.getClass().getName() + ": Exception receive() finally", ex2);

}

}

}

[5845 byte] By [waipuna] at [2007-11-27 5:45:22]
# 1

> $ telnet <mail server IP adddress> 995

> Trying <mail server IP adddress> ...

> telnet: Unable to connect to remote host: Connection refused

>

> It seems the connection to 995 is OK.

There's something very basic about networking that you're not understanding.

The server is clearly refusing to allow you to connect, and yet you think

the connection is OK. It's not.

Talk to your mail server administrator and/or network administrator

to find out why you can't connect.

bshannona at 2007-7-12 15:27:04 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...