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.timeout", "50000"); Session mySession = Session.getDefaultInstance(props, null); Store myStore = mySession.getStore(protocol); myStore.connect (host, username, password); /********throwing connection timedout exception host,user password and iinternet coneection are provided correctly********/ Folder myFolder = myStore.getFolder("INBOX"); if (myFolder == null) { System.err.println ("No default folder available"); return; } System.out.println ("Accessing " + myFolder.getFullName() + " folder"); myFolder.open(Folder.READ_ONLY); int messagecount = myFolder.getMessageCount(); System.out.println (myFolder.getFullName() + " has " + messagecount + " messages."); Message[] message = myFolder.getMessages (); for (int i = 0; i < message.length; i++) { Address[] fromAddr = message[i].getFrom(); System.out.println (fromAddr[0] + ":" + message[i].getSubject()); } myFolder.close(false); } catch (MessagingException me) { System.err.println ("Messaging failure : " + me); } catch (Exception ex) { System.err.println ("Failure : " + ex); } } }