📌  相关文章
📜  TypeError:无法读取未定义的属性“getPlainBody” - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:11.238000             🧑  作者: Mango

代码示例1
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();