My mail client reads mail but does not fetch them from server?

Discussion in 'Java' started by Leon, Sep 29, 2005.

  1. Leon

    Leon Guest

    Hi,

    My java email client can read the messages sent to my acount at my isp. But
    when i use outlook it fetches these messages that has already been reed in
    my java mail client. So it seems that my mail client dont really get these
    messages from the isp server and instead just reads them. What do i do wrong?
    My code to receive message look like this:

    public ReceiveMail(String popServer, String user, String passw)throws NoSuchProviderException,MessagingException{
    Store store=null;
    Folder folder=null;
    try{
    Properties props = System.getProperties();
    Session session = Session.getDefaultInstance(props, null);

    store = session.getStore("pop3");
    store.connect(popServer, user, passw);

    folder = store.getDefaultFolder();

    folder = folder.getFolder("INBOX");

    folder.open(Folder.READ_ONLY);

    Message[] msgs = folder.getMessages();
    for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    getMessageParts(msgs[msgNum]);
    }
    catch(Exception e){}
    public ReceiveMail(String popServer, String user, String passw)throws NoSuchProviderException,MessagingException{
    Store store=null;
    Folder folder=null;
    try{
    Properties props = System.getProperties();
    Session session = Session.getDefaultInstance(props, null);

    store = session.getStore("pop3");
    store.connect(popServer, user, passw);

    folder = store.getDefaultFolder();

    folder = folder.getFolder("INBOX");

    folder.open(Folder.READ_ONLY);

    Message[] msgs = folder.getMessages();
    for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    getMessageParts(msgs[msgNum]);
    }
    catch(Exception e){}
    }
    Leon, Sep 29, 2005
    #1
    1. Advertising

  2. Leon wrote:
    > Hi,
    >
    > My java email client can read the messages sent to my acount at my isp. But
    > when i use outlook it fetches these messages that has already been reed in
    > my java mail client. So it seems that my mail client dont really get these
    > messages from the isp server and instead just reads them. What do i do wrong?
    > My code to receive message look like this:
    >
    > public ReceiveMail(String popServer, String user, String passw)throws NoSuchProviderException,MessagingException{
    > Store store=null;
    > Folder folder=null;
    > try{
    > Properties props = System.getProperties();
    > Session session = Session.getDefaultInstance(props, null);
    >
    > store = session.getStore("pop3");
    > store.connect(popServer, user, passw);
    >
    > folder = store.getDefaultFolder();
    >
    > folder = folder.getFolder("INBOX");
    >
    > folder.open(Folder.READ_ONLY);
    >
    > Message[] msgs = folder.getMessages();
    > for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    > getMessageParts(msgs[msgNum]);
    > }
    > catch(Exception e){}
    > public ReceiveMail(String popServer, String user, String passw)throws NoSuchProviderException,MessagingException{
    > Store store=null;
    > Folder folder=null;
    > try{
    > Properties props = System.getProperties();
    > Session session = Session.getDefaultInstance(props, null);
    >
    > store = session.getStore("pop3");
    > store.connect(popServer, user, passw);
    >
    > folder = store.getDefaultFolder();
    >
    > folder = folder.getFolder("INBOX");
    >
    > folder.open(Folder.READ_ONLY);
    >
    > Message[] msgs = folder.getMessages();
    > for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    > getMessageParts(msgs[msgNum]);
    > }
    > catch(Exception e){}
    > }



    intetsting code - looks like java.

    here is an exercise for you, try to re-write this program in c++ and
    maybe i WILL TAKE ALOOK AT IT.

    you problem is one of those language failure dependend one.... and you
    should start learning c++. get a book,
    puzzlecracker, Sep 29, 2005
    #2
    1. Advertising

  3. Leon

    Leon Guest

    "puzzlecracker" <> wrote:
    >
    >Leon wrote:
    >> Hi,
    >>
    >> My java email client can read the messages sent to my acount at my isp.

    But
    >> when i use outlook it fetches these messages that has already been reed

    in
    >> my java mail client. So it seems that my mail client dont really get these
    >> messages from the isp server and instead just reads them. What do i do

    wrong?
    >> My code to receive message look like this:
    >>
    >> public ReceiveMail(String popServer, String user, String passw)throws

    NoSuchProviderException,MessagingException{
    >> Store store=null;
    >> Folder folder=null;
    >> try{
    >> Properties props = System.getProperties();
    >> Session session = Session.getDefaultInstance(props, null);
    >>
    >> store = session.getStore("pop3");
    >> store.connect(popServer, user, passw);
    >>
    >> folder = store.getDefaultFolder();
    >>
    >> folder = folder.getFolder("INBOX");
    >>
    >> folder.open(Folder.READ_ONLY);
    >>
    >> Message[] msgs = folder.getMessages();
    >> for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    >> getMessageParts(msgs[msgNum]);
    >> }
    >> catch(Exception e){}
    >> public ReceiveMail(String popServer, String user, String passw)throws

    NoSuchProviderException,MessagingException{
    >> Store store=null;
    >> Folder folder=null;
    >> try{
    >> Properties props = System.getProperties();
    >> Session session = Session.getDefaultInstance(props, null);
    >>
    >> store = session.getStore("pop3");
    >> store.connect(popServer, user, passw);
    >>
    >> folder = store.getDefaultFolder();
    >>
    >> folder = folder.getFolder("INBOX");
    >>
    >> folder.open(Folder.READ_ONLY);
    >>
    >> Message[] msgs = folder.getMessages();
    >> for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    >> getMessageParts(msgs[msgNum]);
    >> }
    >> catch(Exception e){}
    >> }

    >
    >
    >intetsting code - looks like java.
    >
    >here is an exercise for you, try to re-write this program in c++ and
    >maybe i WILL TAKE ALOOK AT IT.
    >
    >you problem is one of those language failure dependend one.... and you
    >should start learning c++. get a book,


    Yes, this is a java forum! Maybe you are in the wring place!
    >
    Leon, Sep 29, 2005
    #3
  4. Leon wrote:
    > "puzzlecracker" <> wrote:


    >>you problem is one of those language failure dependend one.... and you
    >>should start learning c++. get a book,

    >
    > Yes, this is a java forum! Maybe you are in the wring place!


    No, puzzlecracker is simply a troll, and a particularly
    ineffectual one at that.
    Andrew Thompson, Sep 29, 2005
    #4
  5. Leon

    Roedy Green Guest

    On 28 Sep 2005 23:18:15 GMT, "Leon" <> wrote or
    quoted :

    > So it seems that my mail client dont really get these
    >messages from the isp server and instead just reads them. What do i do wrong?


    You have to delete them after you have read them. I have found this
    process to be unreliable. I never did nail down why.

    You need some code something like this. I hope somebody can see a bug
    in this:


    /**
    * Shutdown receive session.
    */
    static void close()
    {
    try
    {
    if ( rm != null )
    {
    // shaw won't let us mark deleted.
    /* mark the original message as deleted, whether we
    successfully processed it or not. */
    rm.setFlag( Flags.Flag.SEEN, true );
    rm.setFlag( Flags.Flag.DELETED, true );
    }
    if ( folder != null )
    {
    folder.close( true ); // please delete messages marked
    deleted.
    }
    if ( store != null )
    {
    store.close();
    }
    /* no such thing as session.close(); */
    }
    catch ( Exception e )
    {
    log.println( e.getMessage() );
    e.printStackTrace();
    reason = "Trouble shutting down";
    }
    }

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 29, 2005
    #5
  6. Leon

    zero Guest

    "Leon" <> wrote in
    news:433b24b7$0$24302$:

    >
    > Hi,
    >
    > My java email client can read the messages sent to my acount at my
    > isp. But when i use outlook it fetches these messages that has already
    > been reed in my java mail client. So it seems that my mail client dont
    > really get these messages from the isp server and instead just reads
    > them. What do i do wrong? My code to receive message look like this:
    >
    > public ReceiveMail(String popServer, String user, String passw)throws
    > NoSuchProviderException,MessagingException{
    > Store store=null;
    > Folder folder=null;
    > try{
    > Properties props = System.getProperties();
    > Session session = Session.getDefaultInstance(props,
    > null);
    >
    > store = session.getStore("pop3");
    > store.connect(popServer, user, passw);
    >
    > folder = store.getDefaultFolder();
    >
    > folder = folder.getFolder("INBOX");
    >
    > folder.open(Folder.READ_ONLY);
    >
    > Message[] msgs = folder.getMessages();
    > for (int msgNum = 0; msgNum < msgs.length; msgNum++)
    > getMessageParts(msgs[msgNum]);
    > }
    > catch(Exception e){}
    > }


    First of all, if you open something, close it! you're opening a store
    and a folder, so you need to close them.

    To delete a message from a pop3 server, you only need to mark it as
    deleted. Then, when you close the folder & store, it will be removed
    from the server.

    All you need is three lines of code inside your try block:

    msgs[msgNum].setFlag(Flags.Flag.DELETED, true);

    folder.close(true);
    store.close();

    Also, I hope that catch(Exception e){} is only there for testing
    purposes. Your code can't throw anything if you catch all exceptions.
    zero, Sep 29, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terry Carroll
    Replies:
    10
    Views:
    634
    Fuzzyman
    Jan 23, 2006
  2. Sébastien de Mapias

    IO blocking reads: how do you deal with them ?

    Sébastien de Mapias, May 25, 2009, in forum: Java
    Replies:
    1
    Views:
    343
    Tom Anderson
    May 25, 2009
  3. Biranchi Narayan Panda
    Replies:
    0
    Views:
    533
    Biranchi Narayan Panda
    Feb 21, 2010
  4. Replies:
    0
    Views:
    190
  5. Noggon
    Replies:
    2
    Views:
    112
    Noggon
    Jun 25, 2006
Loading...

Share This Page