将 Google 个文件发送到电子邮件

Send Google file to email

我在 Google 应用程序脚本中构建了一个侧边栏,在执行某些操作时,我想将文档发送到电子邮件,并希望它出现在电子邮件中,就像当您共享文档时,您会得到一种带有文件标题的文档小部件一些文本按钮等。

是否可以附加这样的文件而不是 PDF 文件?

您可以 easily attach a Google Document or any Blob 发送电子邮件,也可以使用以下代码构建包含文档信息的电子邮件 link:

var myDocument = DocumentApp.openById(<DOC_ID>);
var mySpreadsheet = SpreadsheetApp.openById(<SPREADSHEET_ID>);
MailApp.sendEmail({
    to: "recipient@example.com",
    subject: "My Email",
    htmlBody: "Document Name: " + myDocument.getName() + ". " +
              "Document Link: " + myDocument.getURL(),
    attachments: //Or just attach the Docs... If you don't want to, remove this option
      [
        myDocument,
        mySpreadsheet 
      ]
  });

编辑: 显然,htmlBody 使用 HTML 可以像网页一样设置样式。我的例子非常基础。 Google 没有提供标准的卡片或小部件。 他们提供的 HTML 实现非常灵活,因此我们可以创建自己的!那里有很多免费的电子邮件模板,我过去使用过 Litmus 的免费模板。