Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Google Scripts to Archive Specific Email

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!