How to Factory Reset your Gmail Account

Published in: Gmail - Google Apps Script

Your phone, the iPad, and your laptop offer a ‘hard reset’ option that resets your device to the default factory settings. Once you perform a factory reset, it erases all the apps, files, and settings and there’s no way to recover the wiped off data.

Nuke Gmail Account - Remove Everything

What is Gmail Factory Reset

If you ever need to “factory reset” an old Gmail account that you no longer use, and start afresh with a clean slate, Google Scripts can help. The script will perform a series of tasks to completely reset your Gmail account:

  1. Delete all Gmail labels
  2. Delete all Gmail filters
  3. Delete all Draft messages
  4. Delete all email messages in Gmail
  5. Delete all spam messages
  6. Permanently empty your Gmail trash folder
  7. Remove Out-of-Office message
  8. Disables POP and IMAP
  9. Remove all email signatures in Gmail
  10. Stops all email forwarding

⚠️ Warning: Danger Ahead

Before you proceed, please understand that hard reset is an irreversible process and you will not be able to recover your Gmail data after the reset is complete.

The Google Script is available on Github or you can click here to make a copy of the script in your Google account. The script uses the official Gmail API to format your Gmail account.

Remove all Gmail Labels

const deleteGmailLabels = () => {
  GmailApp.getUserLabels().forEach((label) => {

Remove all Gmail Filters

const deleteGmailFilters = () => {
  const { filter: gmailFilters } = Gmail.Users.Settings.Filters.list('me');
  gmailFilters.forEach(({ id }) => {
    Gmail.Users.Settings.Filters.remove('me', id);

Remove all Gmail Drafts

const deleteGmailDrafts = () => {
  GmailApp.getDrafts().forEach((draft) => {

Reset Gmail Settings

Turn off vacation autoresponders, disables IMAP and POP access, removes all email signatures and disables email forwarding.

const resetGmailSettings = () => {
  const { Settings } = Gmail.Users;
  // Disable Out-of-office
  Settings.updateVacation({ enableAutoReply: false }, 'me');

  // Delete Gmail Signatures
  const { sendAs } = Settings.SendAs.list('me');
  sendAs.forEach(({ sendAsEmail }) => {
    Settings.SendAs.update({ signature: '' }, 'me', sendAsEmail);

  // Disable IMAP
  Settings.updateImap({ enabled: false }, 'me');

  // Disable POP
  Settings.updatePop({ accessWindow: 'disabled' }, 'me');

  // Disable Auto Forwarding
  const { forwardingAddresses } = Settings.ForwardingAddresses.list('me');
  forwardingAddresses.forEach(({ forwardingEmail }) => {
    Settings.ForwardingAddresses.remove('me', forwardingEmail);

Delete all Gmail Messages

This will move all inbox messages, archived message, and spam to the trash folder. Google Scripts can execute for 5 minutes in one batch so we added a check to stop the script if it is taking longer to complete.

const startTime =;
const isTimeLeft = () => {
  const ONE_SECOND = 1000;
  return MAX_EXECUTION_TIME > - startTime;

 * Move all Gmail threads to trash folder
const deleteGmailThreads = () => {
  let threads = [];
  do {
    threads ='in:all', 0, 100);
    if (threads.length > 0) {
  } while (threads.length && isTimeLeft());

 * Move all Spam email messages to the Gmail Recyle bin
const deleteSpamEmails = () => {
  let threads = [];
  do {
    threads = GmailApp.getSpamThreads(0, 10);
    if (threads.length > 0) {
  } while (threads.length && isTimeLeft());

Permanently Empty the Trash Folder

 * Permanetly empty the Trash folder
const emptyGmailTrash = () => {
  let threads = [];
  do {
    threads = GmailApp.getTrashThreads(0, 100);
    threads.forEach((thread) => {
      Gmail.Users.Threads.remove('me', thread.getId());
  } while (threads.length && isTimeLeft());

Also see: Archive Old Emails in Gmail

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Gmail - Google Apps Script

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube