Google脚本可格式化通过脚本提取的信息

时间:2018-06-29 13:48:40

标签: google-apps-script

下面的以下脚本将阅读我的电子邮件,并从电子邮件以及邮件的收件人中提取值。我希望将其添加到代码中,以获取收件人的电子邮件地址。

当前,代码将处理:John Doe *** john.doe@gmail.com **** -我只希望代码提取john.doe@gmail.com,而没有箭头括号符号

任何对添加此位置的见解都将受到赞赏!

 // Modified from http://pipetree.com/qmacro/blog/2011/10/automated- 
 email-to-task-mechanism-with-google-apps-script/

// Globals, constants
var LABEL_PENDING = "example label/PENDING";
var LABEL_DONE = "example label/DONE";

// processPending(sheet)
// Process any pending emails and then move them to done
function processPending_(sheet) {

// Date format
var d = new Date();
var date = d.toLocaleDateString();

// Get out labels by name
var label_pending = GmailApp.getUserLabelByName(LABEL_PENDING);
var label_done = GmailApp.getUserLabelByName(LABEL_DONE);

// The threads currently assigned to the 'pending' label
var threads = label_pending.getThreads();

// Process each one in turn, assuming there's only a single
// message in each thread
 for (var t in threads) {
 var thread = threads[t];

// Gets the message body
var message = thread.getMessages()[0].getBody();
var recipient = thread.getMessages()[0].getTo();

// Processes the messages here
orderinfo = message.split("example");
rowdata = orderinfo[1].split(" ");

// Add message to sheet
sheet.appendRow([rowdata[1], recipient]);

// Set to 'done' by exchanging labels
thread.removeLabel(label_pending);
thread.addLabel(label_done);
 }
}

// main()
// Starter function; to be scheduled regularly
function main_emailDataToSpreadsheet() {
// Get the active spreadsheet and make sure the first
// sheet is the active one
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.setActiveSheet(ss.getSheets()[0]);

// Process the pending emails
 processPending_(sh);
}

1 个答案:

答案 0 :(得分:0)

关于最后一条错误消息:

var LABEL_PENDING = "example label/PENDING";
var LABEL_DONE = "example label/DONE";

脚本将搜索名称为“ example label / PENDING”和“ example label / DONE”的标签。您确定标签名称为“ example label / PENDING”或“ example label / DONE”吗?

这是根据您的示例进行的一些修改的代码。您只需要创建标签“ PENDING”并用此标签标记一些邮件即可。

var LABEL_PENDING = "PENDING";

function processPending () {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
// Date format
var d = new Date();
var date = d.toLocaleDateString();

// Get out labels by name
var label_pending = GmailApp.getUserLabelByName(LABEL_PENDING);

// The threads currently assigned to the 'pending' label
var threads = label_pending.getThreads();

// Process each one in turn, assuming there's only a single
// message in each thread
 for (var i = 0; i <threads.length; i++) {
 var thread = threads[i];

// Gets the recipient
var recipient = thread.getMessages()[0].getTo();

// Add recipient to sheet
sheet.appendRow([recipient]);

 }
}