Search code examples
javagmail-imap

How to Delete a Message after Reading it Via Gmail-Imap?


Can some one help me on how to delete a message after reading it.

I am using Gmail-Imap.

I could read the mail, read the attachments, but have no clue on how to delete a message.


Solution

  • Read this SO Post.

    If you're using JavaMail, you should first move it to trash:

    Folder trash = store.getFolder("[Gmail]/Bin");
    for (Message m : msgs) {
        inbox.copyMessages(new Message[] { m }, trash);
    }