如何在谷歌脚本中发送电子邮件时使标题数组变粗?

时间:2016-01-27 17:40:13

标签: google-apps-script

function sendEmail() 
{       
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var fRes1 = ss.getSheetByName("Form Responses 1");
    var email = "xxxxxxx@gmail.com";
    var headers = fRes1.getRange(1,1,1,fRes1.getLastColumn()).getValues()[0];    
    var Row = fRes1.getRange(fRes1.getLastRow(),1,1,fRes1.getLastColumn()).getValues()[0];
    var message = "";
    var subject = "test";

    for(var i in Row) 
    {
        message += headers[i] + ': '+ Row[i] + "\n\n";     
    }

    // Send the email
    MailApp.sendEmail(email, subject, message);  
}

这可以正常发送电子邮件,但我需要将“header [i]”显示为粗体。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

您可以在电子邮件中添加HTML正文

function sendEmail() 
{       
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var fRes1 = ss.getSheetByName("Form Responses 1");
    var email = "xxxxx@gmail.com";
    var headers = fRes1.getRange(1,1,1,fRes1.getLastColumn()).getValues()[0];    
    var Row = fRes1.getRange(fRes1.getLastRow(),1,1,fRes1.getLastColumn()).getValues()[0];
    var message = "";
    var subject = "test";

    for(var i in Row) 
    {
       //<br/> and <b> tags
        message += '<b>'+headers[i] +'</b>: '+ Row[i] + "<br/><br/>";     
    }

    // Send the email
    //MailApp.sendEmail(email, subject, message);  
    MailApp.sendEmail({to: email, subject: subject, htmlBody: message,});
}

进一步阅读HTML email template了解应用脚本。