Removing mail using java Mail

I use java mail to automate Gmail operations. One of the operations is to delete the mail, and I use the following for it -

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

but at the same time my letters are sent only to the spam folder.

I am wondering if there is a direct way to delete mail permanently, instead of first deleting mail from the Inbox, and then looking for letters in the Spam folder and deleting them.

+6
source share
3 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, this page does not give any indication that your approach will move mail to the spam folder; and that means you should see a folder named [Gmail]/Spam ; so maybe this does not apply to your situation, anyway? I think you just need to try your approach and see if it works for you!

+4
source

You said you were trying

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

Have you tried folder.close(true); this will delete all messages using the DELETED flags.

+3
source

Setting the flag in Flags.Flag.DELETED only indicates that the message has been deleted.

You need to call

folder.expunge ();

to actually delete those messages marked as deleted.

0
source

Source: https://habr.com/ru/post/895332/


All Articles