2 Ways to Automatically Delete Emails in Gmail (New and Old Emails)

0


Deleting emails in Gmail is necessary to both declutter and save the already limited space of Gmail. Thankfully, Gmail makes it easy to delete emails, like you can bulk delete emails on the desktop or mobile app. Although, an even easier way to get rid of emails would be to automatically delete emails in Gmail.

However, it isn’t that easy to set up the rules to auto delete emails in Gmail and there isn’t even a built-in way to automatically delete old emails. No worries, today I am going to show you how to auto delete specific new emails and also delete emails older than a specific time period.

Create a Filter to Automatically Delete New Emails

Unsubscribing from newsletters works fine to get rid of annoying promotion spam, but it’s difficult to stop targeted spam. Even if you block the sender, they can still reach you using another email address. This is why automatically deleting emails of a specific nature can make things easier for you. If you don’t want to see specific types of emails, then set up a filter to delete them automatically. Here’s how:

Click on the Show search options button at the end of the search bar at the top and it will open the search filters.

Here you can specify the type of emails using different factors. For example, you can tell what type of keywords the emails may have that you want deleted. After specifying the email type, click on the Create filter button.

Now just select Delete it as the action and then click on Create filter. This will delete all emails that match the email type, incoming and old ones.

gmail-filter-delete-emails-automatically

Email will still be available in the Trash for you to recover later if needed. Although Gmail automatically deletes emails in Trash after 30 days, so make sure you act before they are permanently deleted.

If you ever want to remove this filter, go to Gmail Settings > Filters and Blocked Addresses and delete or edit the filter there.

Use a Google Apps Script to Automatically Delete Old Emails

If you want to automatically delete old emails instead of incoming ones, then that isn’t possible in Gmail currently. However, I can help you create a Google Apps script that will automatically delete emails older than the specified time period. You can create a trigger to run this script at a specific interval to make the process fully autonomous.

Don’t worry, the process to create and run a script is really simple. Below you’ll find the exact steps:

Go to Google Apps Script and click on the New project button in the left panel.

google-apps-script-new-project

Now give a name to the project at the top so you can identify it later and then copy and paste the below-mentioned code in it. Make sure you remove all the already written code and then paste this code.

function deleteOldEmails() {
  var threads = GmailApp.search('older_than:30d');
  for (var i = 0; i < threads.length; i++) {
    threads[i].moveToTrash();
  }
}

In the code, you can edit the 'older_than:30d' part to specify exactly how old emails you want to automatically delete. For example, change it to 'older_than:120d' to delete all emails that are over 120 days old.

add-code-to-automatically-delete-old-emails

Afterward, click on the Save project button at the top to save it.

save-code

Run the Script Automatically

Now you need to create a recurring trigger timer to automatically run this script after a specific time. It could be every few minutes, hours, days, weeks, or even months. To do so, Click on the Triggers option in the left panel and then click on Add Trigger.

create-trigger

Here select the time interval type (hours, weeks, etc.) and the exact time inside that interval. Once selected, click on Save.

automatically-delete-old-emails-at-specific-time

Google will now ask you to select the email address where the script will be applied. When you will provide it, it will warn you that the script isn’t verified. Don’t worry, it’s only because it’s a newly created script for personal use. Just click on Advanced here and then click on Go to (your script name).

authenticate-trigger

That’s it, the script will be created and it will automatically run at the selected intervals. Do keep in mind that the script won’t run immediately, it will wait for the trigger. if you want to test it, open the script again in the editor and click on the Run button at the top.

Final Thoughts

Once the above setup is ready, you won’t have to worry about unwanted emails cluttering your inbox. However, I recommend you keep checking the trash folder from time to time to ensure no important email is deleted. It’s really difficult to recover emails once they are deleted from the Trash folder. This is especially true if you’ll be using the Google Apps Script since many old emails could be required later.

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.

Source
Las Vegas News Magazine

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More