Jump to content

how to solve this run time error

- - - - -

  • Please log in to reply
1 reply to this topic

#1
gcsekhar

gcsekhar

    Newbie

  • Members
  • PipPip
  • 14 posts
import javax.mail.*;


import javax.mail.internet.*;

import java.util.Properties;

public class Access

{

public static void main (String args[])

{

int argc = args.length;

if (argc != 4)

{

System.out.println ("Syntax :");

System.out.println (

"java Access protocol host username password");

return;

}

String protocol = args[0];

String host = args[1];

String username = args[2];

String password = args[3];

try

{

Properties props=System.getProperties();


props.setProperty("mail.store.protocol", "imaps");

props.setProperty("mail.imap.connectiontimeout", "50000");

props.setProperty("mail.imap.timeout", "50000");

Session mySession = Session.getDefaultInstance(props, null);


Store myStore = mySession.getStore(protocol);

myStore.connect (host, username, password);

/***************

exception is 


javax.mail.MessagingException: Connection timed out: connect;

  nested exception is:

        java.net.ConnectException: Connection timed out: connect

        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665)

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

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

        at Access.main(Access.java:279)

Caused by: java.net.ConnectException: Connection timed out: connect

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

        at java.net.PlainSocketImpl.doConnect(Unknown Source)

        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

        at java.net.PlainSocketImpl.connect(Unknown Source)

        at java.net.SocksSocketImpl.connect(Unknown Source)

        at java.net.Socket.connect(Unknown Source)

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

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

        at com.sun.mail.iap.Protocol.<init>(Protocol.java:113)

        at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:110)


        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:632)


***************/

}

catch (MessagingException exe)

{

	exe.printStackTrace();

}

catch (Exception ex)

{

	ex.printStackTrace();

}

}

}

Edited by Roger, 19 July 2011 - 12:21 PM.
added [code] tags


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Is the server also self written, or is it known to be working correctly?
I mean, the amount of possible things that cause this not to work are limited:
  • wrong username
  • wrong password
  • wrong host
  • wrong protocol
  • host malfunction

is it gmail? What's the host you're using?

I can succesfully connect to gmail using your code.

       Properties props = System.getProperties();


        props.setProperty("mail.store.protocol", "imaps");

        props.setProperty("mail.imap.connectiontimeout", "50000");

        props.setProperty("mail.imap.timeout", "50000");

        Session mySession = Session.getDefaultInstance(props, null);


        Store myStore = mySession.getStore("imaps");

        myStore.connect("imap.gmail.com", "user@gmail.com", "pass");






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users