Certain e-mails stop being useful after a certain date, for example: Uber discount codes that I might use, invitations to events that I might attend, etc.

Is there a way to set an expiration date for these e-mails? I'd like them to auto-delete after the Uber code expires, after the events are over, etc.

  • 1
    Do you mean setting up a specific expiration date for each email? That seems hard. Creating a label "temporary" and deleting old emails there after some time (3 months or so) could be made automatic with a script.
    – user135384
    Mar 24, 2018 at 5:29
  • Yes, I was thinking of setting a date for each email. Do you recommend any auto-delete script, though? Your solution seems fine, 1 or 2 months should be enough for most emails
    – user182798
    Mar 25, 2018 at 3:48

1 Answer 1


You can make a Google script to delete old emails with certain labels at script.google.com, like so:

function twenty_day_emails() {  
  var label = GmailApp.getUserLabelByName("Twenty Days");  
  if(label == null){
    GmailApp.createLabel('Twenty Days');
    var delayDays = 20 // Enter # of days before messages are moved to trash   
    var maxDate = new Date(); 
    var threads = label.getThreads();  
    for (var i = 0; i < threads.length; i++) {  
      if (threads[i].getLastMessageDate()<maxDate){  

I have personally created three functions in one script which looks for labels for Five, Ten and Twenty Days.

Then you need to create a trigger to run the script daily or whatever. Unfortunately I can no longer figure out how to do that because Google changed things. You can see a better explanation here https://www.maketecheasier.com/google-scripts-to-automate-gmail/, but the interface they show to add triggers no longer exists. :( I can view and edit my existing triggers at script.google.com/home/triggers, but there is no way to add new ones now!

UPDATE: Oh, if you view the triggers for a specific "project" then the Add Triggers button does appear in the bottom right corner of the page. You can view a projects triggers by clicking on the dot dot dot menu for a particular project under My Projects, or when you are editing the script go to Edit > Current Project's Triggers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.