Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 使用Google AppScript发送Google文档的邮件内容_Google Apps Script_Gmail Api - Fatal编程技术网

Google apps script 使用Google AppScript发送Google文档的邮件内容

Google apps script 使用Google AppScript发送Google文档的邮件内容,google-apps-script,gmail-api,Google Apps Script,Gmail Api,我试图用GAS发送gdocs的内容(不是作为附件),我试图将该文件导出为HTML,然后发送相同的内容。我可以知道还有其他工作吗 function test_mail_() { var id = DocumentApp.getActiveDocument().getId(); var url = "https://docs.google.com/feeds/download/documents/export/Export?id=" + id + "&exportFormat=htm

我试图用GAS发送gdocs的内容(不是作为附件),我试图将该文件导出为HTML,然后发送相同的内容。我可以知道还有其他工作吗

function test_mail_() {
 var id = DocumentApp.getActiveDocument().getId();
 var url = 
 "https://docs.google.com/feeds/download/documents/export/Export?id=" + id + "&exportFormat=html";
 var param = {
  method: "get",
  headers: {
    "Authorization": "Bearer " + ScriptApp.getOAuthToken()
  },
  muteHttpExceptions: true,
 };
 var html = UrlFetchApp.fetch(url, param).getContentText();
 var raw = Utilities.base64EncodeWebSafe("Subject: Test\r\n" +
           "From: " + Session.getActiveUser().getEmail() + "\r\n" +
           "To: test@gmail.com\r\n" +
           "Content-Type: text/html; charset=UTF-8\r\n\r\n" +
            html + "\r\n\r\n");
 var message = Gmail.newMessage();
 message.raw = raw;
 var sentMsg = Gmail.Users.Messages.send(message, 'test@gmail.com'); 
}   


此外,我在文档中插入的图纸不会显示在邮件内容中。

有什么问题?您试图导出文件内容。怎么搞的?内容是否被导出,但不是您想要的方式?我看到您正在获取活动文档。那么,这段代码是否绑定到Google文档?当我发送内容时,我无法导出插入的图形。此外,还有填充,这会使文档的内容看起来很糟糕。我已经用附件@sandygood编辑了这个问题。代码将需要编辑HTML,并删除/添加/更改一些内联CSS设置。在HTML中搜索填充、边距和边框设置。是的。完成了。我很想知道有没有其他方法来获取内容,而不是将其转换为html,因为我无法获取正在导出的图形,并且如果有任何方法可以在google document@Sandygoodi中嵌入html如果没有页眉和/或页脚,您可以尝试您可以尝试
DriveApp.getFileById(id).getAs('application/pdf').getDataAsString();
DriveApp.getFileById(id).getBlob().getDataAsString('utf8')