This tutorial shows you how to read old emails from category Forums by a number of days.
The script is simple and has just one function.
I started like any project with one document and one new script with authorization of Gmail.’
You can read these steps with my old tutorials.
Let’s see the script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function old_days_mails_forums(old_days){ // set old_days to one day var old_days = 1 // get the date var my_date = new Date(); // set my_date one day later my_date.setDate(my_date.getDate()-old_days); // search mails and get in threads var threads = GmailApp.search('category:forums'); // for each threads add it to View Logs for (var i = 0; i < threads.length; i++) { if (threads[i].getLastMessageDate()<my_date){ message=threads[i].getFirstMessageSubject(); Logger.log(message); } } } |
The result can be seen at View – Logs.
You can change this script to delete these emails, using this row of code: threads[i].moveToTrash();.