Auto Deleting Gmail emails after 4 days

I’m working on a project that needs an external MySQL backup sent to an email address as an attachment. This is all working fine. I needed to install mutt on the server and then add this to the successful back up

echo "Hi, This is the database backup" | mutt -a /backups/mysql/a.sql.gz -s "Database backup" --

I needed to set the /etc/Muttrc set copy=no, otherwise I was getting an error message and the database wasn’t sent

This is going to result in the gmail inbox getting pretty full so I set up a script to delete all emails older than 4 days.

First I went to to create a script. I created a blank project and copied the code below. I saved the project and then went to Resources -> current project’s triggers. I set the script to run every 12 hours and that meant that there were some current database backups if anything should happen to the server.

* Adapted from
function cleanUp() {
   var delayDays = 4 // Enter # of days before messages are moved to trash
   var maxDate = new Date();
  //var label = GmailApp.getInboxThreads();
   var threads = GmailApp.getInboxThreads();//label.getThreads();
  for (var i = 0; i < threads.length; i++) {
    if (threads[i].getLastMessageDate()<maxDate)