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

L

Leon

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){}
}
 
P

puzzlecracker

Leon said:
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,
 
L

Leon

puzzlecracker said:
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!
 
A

Andrew Thompson

Leon said:
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.
 
R

Roedy Green

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";
}
}
 
Z

zero

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top