Reputation: 21
I want to build a script in https://script.google.com. The script should search all inbox with different parameters and then delete those findings.
All emails (including labels) email is read, older than 30 days, with the exclusion of one or more particular labels.
This is my solution. But the problem is that it is not searching through labels. Only Inbox. Can you please help with this or if you have a better solution :)
function Delite_old_mail() {
var threads = GmailApp.search('label:inbox is:read older_than:30d -label:"Apple"');
for (var i = 0; i < threads.length; i++) {
threads[i].moveToTrash();
}
}
Upvotes: 2
Views: 1481
Reputation: 41
If you need to search within all mail, remove the inbox label you included in the search query.
function Delite_old_mail() {
var threads = GmailApp.search('is:read older_than:30d -label:Apple');
for (var i = 0; i < threads.length; i++) {
threads[i].moveToTrash();
}
}
Upvotes: 2