Skip to main content

Unable to get javamail POP3Folder to delete any messages

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-05-17

I'm trying to setup some email processing using javamail, but have been completely unable to get it to even delete a message.

	Properties props = System.getProperties();
props.setProperty("mail.pop3.rsetbeforequit", "0");
Session session = Session.getInstance(props, null);
Store store = session.getStore("pop3");
store.connect(account.getHost(), account.getUserid(), account.getPassword());
Folder folder = store.getFolder("INBOX");;
int msgCnt = folder.getMessageCount();

for (int idx = 1; (idx <= msgCnt); idx++) {
Message msg = folder.getMessage(idx);
// Do Stuff here...

// doesn't work
msg.setFlag(Flags.Flag.DELETED, true);

                // doesn't work
// Flags flags = new Flags( Flags.Flag.DELETED);
// folder.setFlags(idx, idx, flags, true);

// doesn't work
// Flags flags = new Flags(Flags.Flag.DELETED);
// Message[] msgs = new Message[1];
// msgs[0] = msg;
// folder.setFlags(msgs, flags, true);


It doesn't seem to matter what I do, the message never gets deleted.

What am I doing wrong?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-05-17

And of course, minutes after posting this, I see the obvious problem.

I was opening the folder READ_ONLY. Changed it to READ_WRITE, and now it works!