This is simple to do.
Open a GAS script in google editor.
You can use the google drive menu New – Google Apps Script or create a new document and use from menu: Tools – Script editor to open a new google apps script editor.
Select Gmail A.P.I. from the menu: Resources – Advanced Google services … to use Gmail features.
Send an email from another account with the text test001catafest in title or body email.
Add this source code in the Google script editor, run it, give the permission to use the script.
1 2 3 4 5 6 7 8 9 10 11 12 | function delete_email_by_search() { // this variable will receive the text from email var labelName = "test001catafest"; // this line of source code will search in Gmail trash //var threads = GmailApp.search("in:trash label:" + labelName); // this line of source code will search on Gmail emails var threads = GmailApp.search(""+labelName); // this loop will remove the mails give by threads for (var i = 0; i < threads.length; i++) { Gmail.Users.Messages.remove('me', threads[i].getId()); } } |
The email received by gmail account is deleted.