Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > My mail client reads mail but does not fetch them from server?

Reply
Thread Tools

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

 
 
Leon
Guest
Posts: n/a
 
      09-28-2005

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){}
}
 
Reply With Quote
 
 
 
 
puzzlecracker
Guest
Posts: n/a
 
      09-29-2005

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,

 
Reply With Quote
 
 
 
 
Leon
Guest
Posts: n/a
 
      09-29-2005

"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!
>


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-29-2005
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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-29-2005
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.
 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      09-29-2005
"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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ajax call to fetch multiple results from multiple queries and showing them 1 by 1 as the results comes. Biranchi Narayan Panda ASP .Net 0 02-21-2010 03:46 PM
IO blocking reads: how do you deal with them ? Sébastien de Mapias Java 1 05-25-2009 01:37 PM
Desktop accesses laptop and reads folders but Laptop only accesses/opens Desktop but cannot read folders, access is denied onclejon Wireless Networking 3 11-01-2006 10:50 PM
Driver no longer reads burned cd's when they are loaded BUT still reads manufactured cd's no prob JD Computer Support 5 04-14-2005 01:50 AM
cd-rom/rw/dvd reads cd-r disks burned with music or software on them, but not software or audio cds effi Computer Information 6 12-01-2004 06:03 AM



Advertisments