Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Gmail message sizes in Google Apps Script

I am not a programmer, but I am meticulous. I copied and pasted the below script in Google Apps Script as a new project titled "Get Gmail message sizes in Google Apps Script". My PC runs Windows 10 Pro 64-bit. My Google Chrome (via which I access the Internet) is up-to-date and I am logged in.

I am showing my project:

function getMsgSize() {
  var msgSizeCount = 0,
    attaSize = 0;
  var threads = GmailApp.search('in all has:attachment -in:inbox AND After:2018/09/20 ')
  for (var i = 0; i < threads.length; i++) {
    var msgId = threads[i].getId();
    var msgSize = Gmail.Users.Messages.get("CurrentUserEmailID", msgId).sizeEstimate;
    msgSizeCount = msgSizeCount + msgSize
    var attachment = GmailApp.getMessageById(msgId).getAttachments()
    if (attachment) {
      for (var j = 0; j < attachment.length; j++) {
        attaSize = attaSize + attachment[j].getSize()
      }
    }
  }
  Logger.log(['Message Size: ' + msgSize / 1024 + 'MB', 'Attachment Size: ' + attaSize / 1024 + 'MB'])
}

After running the project, I am getting this error message:

ReferenceError: Gmail is not defined getMsgSize @ Code.gs:7

The script line 7 involved is:

var msgSize = Gmail.Users.Messages.get("CurrentUserEmailID", msgId).sizeEstimate;

What is wrong with my project that it does not run? How do I define Gmail?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I’d change Gmail to GmailApp on the line that is raising the error:

var msgSize = Gmail.Users.Messages…
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!