简体   繁体   English

使用Google应用脚本创建草稿邮件

[英]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.

相关问题 如何使用谷歌应用程序脚本发送草稿电子邮件 - How to send a draft email using google apps script 如何使用谷歌应用程序脚本获取草稿消息的线程 ID - How to get the threadID for a draft message using google apps script 使用Google Apps脚本在Google Apps帐户中进行邮件迁移 - Mail migration in Google Apps Account using Google Apps Script 谷歌应用程序脚本添加一个组以草拟电子邮件 - google apps script adding a group to draft email 使用 GmailApp 从 Google App 脚本创建 HTML 草稿 - Create HTML Draft from Google App script using GmailApp 使用Google Apps脚本接收邮件后,如何自动创建发件人的联系人 - How to create the contact of the sender automatically when the mail is received using Google Apps Script 如何使用Google Apps脚本将Google文档文本导入电子邮件草稿 - How to Import Google doc text into Email draft using Google Apps Script Google Apps Script:如何使用 Google App Script 从单个 GA 帐户创建用户列表并每月一次将其邮寄到 CSV - Google Apps Script: how to create user list from single GA account using Google App Script and mail it in CSV once a month 使用 Google Apps 脚本在 HTML 表单提交上触发邮件发送 - Triggering mail sending on HTML form submit using Google Apps Script 使用HTML正文在Google Apps脚本中使用发送邮件 - Sending mail with HTML body using for in Google Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM