How to use 'Mark emails as "spam"' option for Gmail account using Java Mail API?

356 views Asked by At

I'm currently working on developing an Email Parsing application using the Java Mail API.

The email service I'm using is Gmail. The 'Mark as SPAM' option seems available only on the Gmail interface. The only action I can perform using the Java Mail API is to move the suspicious emails to SPAM folder. However, this does NOT prevent emails from the spam email ids from appearing back in the INBOX.

So for now I'm maintaining an updated list of spam ids which I check against while going through the Inbox folder. If the 'from' email id is present in the list then I use the following code snippet:

folder.copyMessages(msgs, spamFolder); //Moves email msg to SPAM folder

Does anyone know how I can achieve the 'Mark as SPAM' utility using Java Mail API? Does it guarantee that emails from the same ids won't appear in Inbox again? I've seen similar posts on this but with no answers.

1

There are 1 answers

1
Bill Shannon On

There's no way to do that with JavaMail. As far as I know, the Gmail "mark as spam" feature is a Gmail-proprietary feature that's not exposed through the IMAP protocol interface.