Looking for GmailThread.moveToCustomLabel() - Moving thread from Inbox to Custom Label

222 views Asked by At

Per Google Thread API

there are methods to move a thread to Archive,Inbox,Spam,Trash. However, I would like to move a thread from Inbox to a custom label created by me. Is there a way to achieve this with Google App API ?

Thanks

2

There are 2 answers

2
DDD On

Have you tried the addLabel method?

0
Daniel Albert On
let billsLabel = GmailApp.getUserLabelByName("Bills");
if (!billsLabel) {
    label = GmailApp.createLabel(billsLabel);
}
thread.addLabel(billsLabel);
thread.moveToArchive();

You can achieve this by first adding a label to the thread. Then Archiving the thread this will move the email thread to the custom label. The first time I tried this I thought it didn't work. But once I refreshed the inbox and the custom label, I could see it worked.