Gmail – How to permanently delete Gmail spam

gmailgmail-filtersspam-prevention

Can there be a Gmail Gadget App that permanently blocks or deletes spam?

Phong mentions the following in his answer to the question How can I auto-delete some spam from Gmail?

If cluttering your Trash is not desirable, you could filter those messages to a temporary label instead, then use an Apps Script to periodically delete "old" filtered spam from that label. That would ensure that the top of your Trash is clutter-free. If the volume of spam you receive is limited however, deleting might work just fine.

But I don't know how one would "use an Apps Script" for this purpose.

Best Answer

The suggestion you quoted cannot be implemented: Apps Script can move threads to Trash or Spam but cannot delete them permanently. Source: a Google employee's answer on Stack Overflow:

It is not possible, by design, to delete an email permanently using GmailApp.

If you wonder why this restriction is in place, imagine that you made an error coding your script (e.g., put == instead of != somewhere), causing it to delete all of your emails forever with no option for recovery.


So, you have to either:

  1. Move spam to Spam folder and wait 30 days for it to be deleted (note that Spam is separate from Trash, so "cluttering your Trash" is not an issue)
  2. Delete manually
  3. Have a browser-automation script deleting messages as you, i.e., logging in to Gmail through a browser and "clicking" buttons in the interface. This sort of automation has more to do with a particular browser than with web application.