I try to create a script that runs once every day to archive all my LinkedIn digest emails from a specific label IF they are older than a set date (i.e. 14) AND the sender's email address is equal to the one I specified. Here is my code:
const autoArchiveLinkedInDigest = () => {
const daysOlderThan = 14;
const currentDate = new Date();
const oldDate = currentDate.setDate(currentDate.getDate() - daysOlderThan);
const sender = "jobalerts-noreply@linkedin.com";
const label = GmailApp.getUserLabelByName("myLabel");
const threads = label.getThreads();
for (let i=0; i < threads.length; i++ ) {
if (threads[i].getLastMessageDate() < oldDate && threads[i].getMessages()[0].getFrom() == sender) {
threads[i].moveToArchive();
Logger.log(threads[i])
}
}
}
However, it doesn't seem to work for me. I gave permission to access my account and set up a scheduler to run the script in the desired interval. I'm not all new to javascript, but newer worked with Google Scripts. What do I miss here? Thanks for your help in advance!