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?
I'd change Gmail to GmailApp on the line that is raising the error:
var msgSize = Gmail.Users.Messages…
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.