会員登録(無料)
ログイン
Improve your skills, click here now!

[GAS] How to delete all labels created in Gmail | [Caution]

For example, it is a method that can be used when you want to delete the label created in Gmail at once.

Function to delete Gmail label|deleteLabel()

GAS has a function for removing Gmail labels.

deleteLabel()

You can use this to delete currently created labels.

Get current labels (GmailApp.getUserLabels)

First, get the current label. Labels can be obtained using “GmailApp.getUserLabels()”.

function deleteAllLabel() {
const labels = GmailApp.getUserLabels();
}

Now you can get the current label.

function deleteAllLabel() {
const labels = GmailApp.getUserLabels();
 for(let i=0;i<labels.length;i++) {
    Logger.log(labels[i].getName());
  }
}

Delete a label (deleteLabel())

Remove the label. Labels can be deleted with “deleteLabel()”.

function deleteAllLabel() {
const labels = GmailApp.getUserLabels();
 for(let i=0;i<labels.length;i++) {
    labels[i].deleteLabel();
  }
}

Try running the script.

All labels removed!

summary

I was able to remove the label at once! However, once you execute it, you will not be able to restore it, so be very careful when doing this.

Please refer to it