TypeError: Cannot read property 'getPlainBody' of undefined
var emailBody = messages[j].getPlainBody();
Logger.log("Email body: " + emailBody);
var message_account = "", message_date = "", message_vendor = "", message_amount = "";
// Get account number
const regExpAcct = /Account ending in (\d{4})/;
var message_account_m = regExpAcct.exec(emailBody);
if(message_account_m){ message_account = message_account_m[1]; Logger.log("Email message accnt: " + message_account); }
// Get date of transaction
var regExpDate = /we're notifying you that on (...+), at/;
var message_date_m = regExpDate.exec(emailBody);
if(message_date_m){ message_date = message_date_m[1]; Logger.log("Email message date: " + message_date); }
// Get vendor name
var regExpVendor = /, at (...+),/;
var message_vendor_m = regExpVendor.exec(emailBody);
if(message_vendor_m){ message_vendor = message_vendor_m[1]; Logger.log("Email message vendor: " + message_vendor); }
// Get transaction amount
const regExpAmount = /purchase in the amount of \$(\S+) was/;
var message_amount_m = regExpAmount.exec(emailBody);
if(message_amount_m){ message_amount = message_amount_m[1]; Logger.log("Email message amount: " + message_amount); }
addDataToSpreadsheet( message_date, message_account, message_vendor, message_amount);
messages[j].markRead();