Go to https://script.google.com
Then create a new project and paste the below into it:
function removeMyTest2() {
var mymail = "[email protected]"; // Edit this line
var mylabel = "trash";
var permanentlyRemoveMyLabel = true;
var pageToken;
do {
var threadList = Gmail.Users.Threads.list('me', {
q: 'in:' + mylabel,
pageToken: pageToken
});
if (threadList.threads && threadList.threads.length > 0) {
threadList.threads.forEach(function(thread) {
Logger.log('id: %s snippet: %s', thread.id, thread.snippet);
if (permanentlyRemoveMyLabel) {
Gmail.Users.Threads.remove(mymail, thread.id);
Logger.log('id: %s snippet: %s REMOVED', thread.id, thread.snippet);
}
});
}
pageToken = threadList.nextPageToken;
} while (pageToken);
}
If you try and run the script as is it will error out.
Next you click on Resources and go to Advanced Google Services.
Scroll down to Gmail API and turn that on.
Then click on the menu Edit and go to Current project's triggers.
Set a trigger to run the script either every minute/hour or whatever time interval that you want the script to run and empty your trash.
Keep in mind you can delete from IN:TRASH
IN:SPAM
or whatever other label you want. It won't delete reminders and the deletion is final. You can't recover any of the emails.
Editors note:
From https://developers.google.com/apps-script/guides/services/advanced#requirements
Requirements
Before you can use an advanced service, you must satisfy the following requirements:
- You must enable the advanced service in your script project.
- You must make sure the API corresponding to the advanced service is enabled in the Cloud Platform (GCP) project your script uses.
If your script project uses a default GCP project created on or after April 8, 2019, the API is enabled automatically after you enable the advanced service and save the script project. If you have not done so already, you may also be asked to agree to the Google Cloud Platform and Google APIs Terms of Service as well.
If your script project uses a standard GCP project or an older default GCP project, you must enable the advanced service's corresponding API in the GCP project manually. You must have edit access to the GCP project to make this change.
See Cloud Platform projects for more information.