Javascript 如何使用粗体文本通过电子邮件发送google表单数据

Javascript 如何使用粗体文本通过电子邮件发送google表单数据,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我目前正在使用以下脚本让谷歌电子表格通过电子邮件将我的谷歌表单回复发送给我。电子邮件中的所有文本都是纯文本,但我希望标题是粗体文本。我已经尝试过在代码中添加用于粗体文本的java命令来实现这一点,但我基本上是在猜测,因为我没有任何代码编写经验。有可能吗?我的脚本应该如何成功?多谢各位 function sendFormByEmail(e) { var emailSubject = "MOD Report"; // Set with your email address

我目前正在使用以下脚本让谷歌电子表格通过电子邮件将我的谷歌表单回复发送给我。电子邮件中的所有文本都是纯文本,但我希望标题是粗体文本。我已经尝试过在代码中添加用于粗体文本的java命令来实现这一点,但我基本上是在猜测,因为我没有任何代码编写经验。有可能吗?我的脚本应该如何成功?多谢各位

function sendFormByEmail(e) {
    var emailSubject    = "MOD Report";  

    // Set with your email address or a comma-separated list of email addresses.
    var yourEmail       = "xxxx@xxxx.com";

    // Set with your spreadsheet's key, found in the URL when viewing your spreadsheet.
    var docKey          = "xxxx-xxxx-xxxx-xxxx";

    // If you want the script to auto send to all of the spreadsheet's editors, set this value as 1.
    // Otherwise set to 0 and it will send to the yourEmail values.
    var useEditors      = 0;

    // Have you added columns that are not being used in your form? If so, set this value to 
    // the NUMBER of the last column that is used in your form.
    // for example, Column C is the number 3
    var extraColumns    = 0;

    if (useEditors) {
        var editors = DocsList.getFileById(docKey).getEditors();
        if (editors) { 
            var notify = editors.join(',');
        } else var notify = yourEmail;
    } else {
        var notify = yourEmail;
    }

    // The variable e holds all the submission values in an array.
    // Loop through the array and append values to the body.

    var s = SpreadsheetApp.getActive().getSheetByName("FormResponses1");
    if (extraColumns){
        var headers = s.getRange(1,1,1,extraColumns).getValues()[0];
    } else var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];

    var message = "";
    for(var i in headers) {
        message += headers[i] + ' = '+ e.values[i].toString() + '\n\n'; 
    }

    MailApp.sendEmail(notify, emailSubject, message); 
}

您需要使用htmlBody高级参数

下面是一些示例代码: 注意:HTML粗体标记:
此处的文本

函数sendmail(){ var message=“这就是消息”; MailApp.sendmail({ 至:theEmail@example.com", 主题:“这是主题行”, htmlBody:“
”+ “内联文本”+ 消息 }); }
您需要替换此代码段:

for(var i in headers) {
    message += headers[i] + ' = '+ e.values[i].toString() + '\n\n'; 
}

MailApp.sendEmail(notify, emailSubject, message); 
为此:

for(var i in headers) {
    message += "<b>" + headers[i] + '</b> = '+ e.values[i].toString() + '<br>'; 
}

MailApp.sendEmail(notify, emailSubject, "", {htmlBody:message}); 
for(标题中的变量i){
消息+=''+头[i]+'='+e.values[i].toString()+'
'; } sendmail(notify,emailSubject,“,{htmlBody:message});
我认为电子邮件客户端显示的文本被
*
包围,并且
*
呈现为粗体。您可以尝试将其用于标题。这非常接近于一种解决方案,但是,它没有将标题设置为粗体,而是将所有表单响应设置为粗体,而将标题保留为纯文本。
for(var i in headers) {
    message += "<b>" + headers[i] + '</b> = '+ e.values[i].toString() + '<br>'; 
}

MailApp.sendEmail(notify, emailSubject, "", {htmlBody:message});