[英]Create draft mail using Google apps script
I want to know if it's possible to create draft mail using Google Apps script. 我想知道是否可以使用Google Apps脚本创建草稿邮件。 And if yes, how is it possible ?
如果是的话,怎么可能呢?
Regards, Sebastien 此致,塞巴斯蒂安
At this point in time, there is no way to create a new message that appears in your Drafts
folder. 此时,无法创建出现在
Drafts
文件夹中的新消息。 This functionality has been requested previously - see Issue 985 . 之前已请求此功能 - 请参阅问题985 。 If you are interested in receiving any updates, visit and star the issue.
如果您有兴趣接收任何更新,请访问并加注问题。
EDIT: While still not natively supported in Google Apps Script, you can create drafts by using the GMail API, using getOAuthToken()
to authenticate (introduced Feb 2014). 编辑:虽然Google Apps脚本仍然不支持,但您可以使用GMail API创建草稿,使用
getOAuthToken()
进行身份验证(2014年2月推出)。 Drafts support was added to the API in June 2014, and an example of its use from GAS is shown in comment 29 of the above issue. 2014年6月在API中添加了草稿支持,并且在上述问题的评论29中显示了其在GAS中使用的示例。 Code reproduced here for convenience:
为方便起见,此处转载的代
function createDraft() {
var forScope = GmailApp.getInboxUnreadCount(); // needed for auth scope
var raw =
'Subject: testing Draft\n' +
//'To: test@test.com\n' +
'Content-Type: multipart/alternative; boundary=1234567890123456789012345678\n' +
'testing Draft msg\n' +
'--1234567890123456789012345678--\n';
var draftBody = Utilities.base64Encode(raw);
var params = {method:"post",
contentType: "application/json",
headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions:true,
payload:JSON.stringify({
"message": {
"raw": draftBody
}
})
};
var resp = UrlFetchApp.fetch("https://www.googleapis.com/gmail/v1/users/me/drafts", params);
Logger.log(resp.getContentText());
/*
* sample resp: {
* "id": "r3322255254535847929",
* "message": {
* "id": "146d6ec68eb36de8",
* "threadId": "146d6ec68eb36de8",
* "labelIds": [ "DRAFT" ]
* }
* }
*/
}
Google added support for generating drafts in September 2017. From the documentation : 谷歌在2017年9月增加了对草稿的支持。来自文档 :
// The code below creates a draft email with the current date and time.
var now = new Date();
GmailApp.createDraft("mike@example.com", "current time", "The time is: " + now.toString());
No. It is not possible to do so. 不可以。不可能这样做。 See the documentation .
请参阅文档 。
I do this via Zapier now - it's fantastic. 我现在通过Zapier做到这一点 - 太棒了。
See this zap http://zpr.io/fhmT 看到这个zap http://zpr.io/fhmT
Google's documentation on the subject is here: Google有关此主题的文档如下:
https://developers.google.com/gmail/api/guides/drafts https://developers.google.com/gmail/api/guides/drafts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.