Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: what's wrong with my code

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what's wrong with my code

    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);
    }
    }
    }


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default 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.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default 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.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. want wrong with my code
    By drum in forum Member Introductions
    Replies: 1
    Last Post: May 20th, 2011, 09:06 AM
  2. What's Wrong With My Code?
    By arunjib in forum What's Wrong With My Code?
    Replies: 18
    Last Post: May 7th, 2011, 08:47 PM
  3. What's wrong with my code?
    By lindmando in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 7th, 2011, 10:13 PM
  4. what's wrong in this code
    By Aravind in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2011, 02:38 AM
  5. What's wrong with my code ?
    By mithani in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 5th, 2010, 08:57 AM