Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting mail permanently using java Mail

I have been using java mail to automate Gmail operations. One of the operation is to delete mail and I use following for it -

message.setFlag(Flags.Flag.DELETED, true);

but doing so only pushes my mails to spam folder.

I am wondering if there is a straight way to delete mail permanently instead of deleting mail from "inbox" first and then searching mails in "spam " folder and deleting them.

like image 537
Tarun Avatar asked Aug 18 '11 14:08

Tarun


People also ask

Can we delete mails permanently?

Scroll to Trash. Check the box next to messages you want to permanently delete. Then click Delete forever.

How do I permanently delete emails from server?

At the top of your inbox, above the message list, select the check box. Above the message list, select Delete. All the email in your inbox will be moved to the Deleted Items folder. To permanently delete the messages, right-click the Deleted Items folder and select Delete all.

How do I delete all emails from IMAP?

IMAP accounts provide several options to delete messages that aren't available in POP accounts. Tools -> Account Settings -> Account Name -> Server Settings -> "When I delete a message" has choices for "Move it to the Trash folder", "Mark it as deleted" and "Remove it immediately".

How do I empty my mailbox all at once?

Deleting all your emails in Gmail is simple: open Gmail, select the inbox tab you want to clear out (Primary, Promotions, etc.) and click the small empty box in the top left corner, just above the Compose button. This will select everything on the current page of your inbox.


2 Answers

According to http://mail.google.com/support/bin/answer.py?answer=78755:

If you want to delete a message from all folders, move it to the [Gmail]/Trash folder.

If you delete a message from [Gmail]/Spam or [Gmail]/Trash, it will be deleted permanently.

However, that page doesn't give any indication that your approach would move mail to the spam folder; and it implies that you should see a folder named [Gmail]/Spam; so maybe it doesn't apply to your situation, somehow? I think you'll just have to try its approach, and see whether it works for you!

like image 128
ruakh Avatar answered Oct 07 '22 03:10

ruakh


You told that you are trying

 message.setFlag(Flags.Flag.DELETED, true);

did you tried folder.close(true); this will expunge all messages with DELETED flags.

like image 28
Gagan Tiwari Avatar answered Oct 07 '22 03:10

Gagan Tiwari