what's wrong with my code
Code Java:
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);
}
}
}
Re: what's wrong with my code
You tell us what is wrong with your code...does it compile? Are there exceptions? Does it misbehave? And please wrap your code in the code tags.
Re: what's wrong with my code
gcsekhar, you can't just post some code and expect people to attempt to compile it with no proper explanation about the issues from yourself.
Please make sure you give us as much information as possible.
What is this program meant to do? What doesn't work? Where are you stuck?! etc.
This is the only way to guarantee quality replies.