8

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.

Tarun
  • 3,456
  • 10
  • 48
  • 82
  • May be a different question but I can not use Folder spam = store.getFolder("[Gmail]/Spam"); to get mails from spam folder.... What could be folder name for "spam" folder – Tarun Aug 18 '11 at 15:01
  • 5
    I hope the following post has the answer [http://stackoverflow.com/questions/1464706/delete-email-on-server-using-javax-m][1] [1]: http://stackoverflow.com/questions/1464706/delete-email-on-server-using-javax-mail –  Aug 18 '11 at 15:03

3 Answers3

4

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!

ruakh
  • 175,680
  • 26
  • 273
  • 307
3

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.

Gagan Tiwari
  • 212
  • 2
  • 16
0

Setting the flag to Flags.Flag.DELETED only marks the email as deleted.

You need to call

folder.expunge();

to actually expunge those emails marked as deleted.

GoYun.Info
  • 1,356
  • 12
  • 12