Deleting all email messages

Top  Previous  Next

As a convenience you may mark all messages retrieved during an IMAP session for deletion by invoking the Imap#setDelete method and passing an argument value of true. You must do this prior to retrieving any messages from the mailbox. If the Imap#setDelete method is given an argument of true then upon invoking the Imap#expunge method all messages retrieved from the mailbox will be deleted.

 

Example

 

// establish connection

imap.connect();

 

// mark messages retrieved for deletion upon logout

imap.setDelete(true);

 

// get messages in mailbox

Enumeration e = imap.getMessages();

 

// loop thru all messages in mailbox ... each is flag for deletion upon retrieval

while(e.hasMoreElements()) {

 EmailMessage message = (EmailMessage)e.nextElement();

}

 

// delete messages marked for deletion and logout

imap.expunge();

imap.disconnect();





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC