本文介绍了使用Google应用程序脚本创建草稿邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想知道是否可以使用Google Apps脚本创建草稿邮件。
如果是的话,怎么可能?

I want to know if it's possible to create draft mail using Google Apps script.And if yes, how is it possible ?

问候,
Sebastien

Regards,Sebastien

推荐答案

此时,无法创建出现在草稿箱文件夹中的新消息。此功能已被请求 - 请参阅。如果您有兴趣收到任何更新,请访问并发布相关问题。

At this point in time, there is no way to create a new message that appears in your Drafts folder. This functionality has been requested previously - see Issue 985. If you are interested in receiving any updates, visit and star the issue.

编辑:虽然Google Apps脚本尚未原生支持,但您可以使用GMail API创建草稿,使用 getOAuthToken()进行身份验证(2014年2月推出)。草稿支持已于2014年6月添加到API中,并且来自GAS的使用示例显示在以上问题。代码转载在这里为了方便:

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). 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. Code reproduced here for convenience:

function createDraft() {

  var forScope = GmailApp.getInboxUnreadCount(); // needed for auth scope

  var raw =
      'Subject: testing Draft\n' +
      //'To: [email protected]\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应用程序脚本创建草稿邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:02