使用Google Apps脚本发送带有格式化数据的邮件

时间:2019-05-20 08:26:53

标签: google-apps-script

嗨,我正在使用附加到Google Apps脚本的自定义表单来处理表单

部分形式: part of the form

因此该表单调用了processForm函数,该函数正在调用formatMailBody,该函数正在构建一个曾经是邮件正文的字符串

function processForm(e) {
  var lock = LockService.getPublicLock();
  lock.waitLock(30000);

  try {
    var requestID = record_data(e); // this function doesn't matter here
    var mailData = e;
    MailApp.sendEmail({
      to: TO_ADDRESS, //Recipients emails
      subject: 'blabla'
      htmlBody: formatMailBody(requestID, mailData) // THE PROBLEM lie in this function
    })

    // return json success results
    return ContentService
    .createTextOutput(JSON.stringify({'result':'success', 'sampleMaterialReference':e['sampleMaterialReference'] }))
    .setMimeType(ContentService.MimeType.JSON);

  } catch(error) { // if error return this
    Logger.log(error);
    return ContentService
    .createTextOutput(JSON.stringify({'result':'error', 'error': e}))
    .setMimeType(ContentService.MimeType.JSON);
  } finally { //release lock
    lock.releaseLock();
  }
}

function formatMailBody(id, obj) {

  var result = 'construct the body of the email'
  result+='<td bgcolor=\''+rowColor+'\'>'+obj["sampleType"]+'</td>'

  Logger.log(obj);
  Logger.log('<td bgcolor=\''+rowColor+'\'>'+obj["sampleType"]+'</td>');

  return result;
}

Logger.log的结果,格式为MailBody: result of Logger.log in formatMailBody

发送给某人的邮件结果: result of mail send to somebody

所以这里的问题在于机体邮件的数组,应该是样本类型:test,而不是样本类型:t,有解决方案吗?

0 个答案:

没有答案