我有帶有徽標和一些影像以及一些文本說明的谷歌檔案模板,我想通過電子郵件發送它在谷歌檔案中的顯示方式,我知道如何從谷歌檔案發送純文本,但不知道如何發送帶有影像的模板。
這是我目前使用的代碼:-
var body = doc.getBody().getText();
var message = body;
var subject = "subject line";
MailApp.sendEmail (user.primaryEmail, subject, message)
Tanaike 建議的更新腳本:-
function getDocAsHtml(docId){
var doc = DocumentApp.getActiveDocument()
var url = "https://docs.google.com/feeds/download/documents/export/Export?exportFormat=html&id=" doc.getId();
var html = UrlFetchApp.fetch(url, { headers: { authorization: "Bearer " ScriptApp.getOAuthToken() } }).getContentText();
var body = doc.getBody().getText();
var message = body;
var subject = "subject line";
MailApp.sendEmail('[email protected]', subject, message, { htmlBody: html });
}
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您希望將電子郵件作為 Google 檔案的 HTML 正文發送。
在這種情況下,如何進行以下修改?從您的顯示腳本中,我想那doc是 Document 的物件。
修改后的腳本:
var url = "https://docs.google.com/feeds/download/documents/export/Export?exportFormat=html&id=" doc.getId();
var html = UrlFetchApp.fetch(url, { headers: { authorization: "Bearer " ScriptApp.getOAuthToken() } }).getContentText();
var body = doc.getBody().getText();
var message = body;
var subject = "subject line";
MailApp.sendEmail(user.primaryEmail, subject, message, { htmlBody: html });
// DriveApp.getFiles(); // This is used for automatically detecting the scope of Drive API.
- 運行此腳本時,Google 檔案
doc將作為 HTML 正文發送。
筆記:
- 在這種情況下,郵件客戶端無法顯示 HTML 正文,顯示的是文本正文
message。
參考:
- 獲取(網址,引數)
- sendEmail(收件人、主題、正文、選項)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/487907.html
上一篇:GoogleAppsScriptDocsAdd-on側邊欄為空白
下一篇:應用腳本日期格式問題
