Home > Blockchain >  Adding a tag to an email file creates an error
Adding a tag to an email file creates an error

Time:06-13

I created a script that receives last minute emails if they do not contain a "a" tag and sends the content of the message to a function I called "ssfunction" and then adds the "a" tag to it And this is the script I made:

const threads = GmailApp.search('-{label:a}');
 for (const thread of threads) {
   const messages = thread.getMessages();
   const minuteAgo = new Date(Date.now() - 60000);
   if (thread.getLastMessageDate() > minuteAgo) {
     for (const message of messages) {
       if (message.getDate() > minuteAgo) {
       const result = ssfunction(message);
       didUpload = result || didUpload;
       }
     }
     thread.addLabel("a");
   } else {
     const result = ssfunction(messages[messages.length - 1]);
     didUpload = result || didUpload;
     thread.addeLabel("a");
   }

But I get such an error: TypeError: thread.addeLabel is not a function Thank you so much for all the willingness to help

CodePudding user response:

In your script, I thought that the method name of addeLabel is required to be modified to addLabel. I think that this is the reason of your error message. And, in the case of addLabel, the argument is GmailLabel object. When these points are reflected in your script, it becomes as follows.

From:

thread.addeLabel('a');

To:

var label = GmailApp.getUserLabelByName("a");
thread.addLabel(label);

Refernce:

  • Related