Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 185547
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T01:03:13+00:00 2022-06-10T01:03:13+00:00

javascript – Pulling numbers between white space from email body into google sheets

  • 0

[ad_1]

I am trying to pull a 6 digit number(authentication code)between white space from the email body into a google sheet. “date, sender, and subject” are all populating in the google sheet correctly except “body”, which is populating ” [Ljava.lang.Object;@6f90342a “. Here is my full code and a screenshot of the email body.

 function getGmailEmails(){
      var input = ui.prompt('Label Name', 'Enter the label name that is assigned to your emails:', Browser.Buttons.OK_CANCEL);
      
      if (input.getSelectedButton() == ui.Button.CANCEL){
        return;
      }
      
      var label = GmailApp.getUserLabelByName(input.getResponseText().trim());
      var threads = label.getThreads();
      
      for(var i = threads.length - 1; i >=0; i--){
        var messages = threads[i].getMessages();
        
        for (var j = 0; j <messages.length; j++){
          var message = messages[j];
          if (message.isUnread()){
            extractDetails(message);
            GmailApp.markMessageRead(message);
            }
        }
        threads[i].removeLabel(label); //delete the label after getting the message    
      }  
    }
          function extractDetails(message){
          
          var emailData = {
            date: "Null",
            sender: "Null",
            subject: "Null",
            body: "Null",
          }
           regExp = /(\b(\d+)\b)/;
     
          emailData.date = message.getDate();
          emailData.subject = message.getSubject();
          emailData.sender = message.getFrom();
          main = message.getPlainBody();
          emailData.body = main.match(regExp);
  var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  var emailDataArr = [];
  
  for(var propName in emailData){
    emailDataArr.push(emailData[propName]);
  }
  activeSheet.appendRow(emailDataArr);

email body example and regexp

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 396 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 370 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 361 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.