Gle*_*tle 4 google-apps-script
有没有一种方法可以将Google文档嵌入电子邮件中?
我可以从:
var doc = DocumentApp.openById('1P_KZr_xpg.....xntBqvQ');
Run Code Online (Sandbox Code Playgroud)
我尝试过这些方法:
A)MailApp.sendEmail('john@abc.com', doc.getName(), doc.getText());
文档中的原始文本构成了电子邮件的正文...所有格式都丢失了.
B)MailApp.sendEmail('john@abc.com', doc.getName(), doc.getUrl());文档的URL是消息的主体.在您单击源文档之前,不会看到文档的内容.
C)MailApp.sendEmail('john@abc.com', doc.getName(), '', { htmlBody: HtmlService.createHtmlOutput(doc.getAs('blob') });这似乎很有希望,但是给出了一个错误:"请求的转换不受支持."
有没有其他方法来嵌入文档?
有没有办法获得文档的HTML版本?一旦我有了,我可以htmlBody用来插入它.
这已经回答了几次,这里是Henrique Abreu 最初建议的代码(不关心评论说它不起作用,确实如此!):
function emailDocTest() {
var id = 'Doc-Very-Long-ID-Here';
var url = 'https://docs.google.com/feeds/';
var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,
googleOAuth_('docs',url)).getContentText();
var emailAdress = Session.getEffectiveUser().getEmail();
MailApp.sendEmail(emailAdress, 'test doc send by mail as html', 'html only', {htmlBody:doc});
}
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey('anonymous');
oAuthConfig.setConsumerSecret('anonymous');
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
Run Code Online (Sandbox Code Playgroud)
请注意,googleOAuth_函数需要一个特殊授权,只能使用脚本编辑器激活该函数来运行该函数(不是来自UiApp或菜单),并且此函数不会出现在"运行"列表中,因为在其名称的末尾加上下划线(这就是它的工作方式),所以至少从脚本编辑器运行一次并记住,如果/当你最终与其他人共享应用程序时.有关详细信息,请参阅功能请求677
| 归档时间: |
|
| 查看次数: |
4591 次 |
| 最近记录: |