【问题标题】:Gmail addon createdraftreply() replying to yourselfGmail 插件 createdraftreply() 回复自己
【发布时间】:2018-02-27 22:13:53
【问题描述】:

我参考的是官方指南 here

创建回复草稿。

  var composeAction = CardService.newAction()
      .setFunctionName('createReplyDraft');
  var composeButton = CardService.newTextButton()
      .setText('Compose Reply')
      .setComposeAction(composeAction, CardService.ComposedEmailType.REPLY_AS_DRAFT);

  // ...

  /**
   *  Creates a draft email (with an attachment and inline image)
   *  as a reply to an existing message.
   *  @param {Object} e data passed by the compose action.
   *  @return {ComposeActionResponse}
   */
  function createReplyDraft(e) {
    // Activate temporary Gmail add-on scopes, in this case to allow
    // a reply to be drafted.
    var accessToken = e.messageMetadata.accessToken;
    GmailApp.setCurrentMessageAccessToken(accessToken);

    // Creates a draft reply.
    var messageId = e.messageMetadata.messageId;
    var message = GmailApp.getMessageById(messageId);
    var draft = message.createDraftReply('',
        {
            htmlBody: "Kitten! <img src='cid:kitten'/>",
            attachments: [
              UrlFetchApp.fetch('https://example.com/images/myDog.jpg')
                  .getBlob()
            ],
            inlineImages: {
              "kitten": UrlFetchApp.fetch('https://example.com/images/myKitten.jpg')
                           .getBlob()
            }
        }
    );

    // Return a built draft response. This causes Gmail to present a
    // compose window to the user, pre-filled with the content specified
    // above.
    return CardService.newComposeActionResponseBuilder()
        .setGmailDraft(draft).build();
  }

当线程中的最后一条消息来自另一个人时,它可以正常工作, 但是当最后一条信息来自你自己时, 新草稿的收件人地址是您的地址,而不是其他人。

1.

(最后一条消息)其他人→我

createDraftReply()

(草稿)我→其他人

2.

(最后一条消息)我→其他人

createDraftReply()

(草稿)我→我

如何创建具有正确收件人的回复草稿?

【问题讨论】:

    标签: gmail-addons


    【解决方案1】:

    在创建回复草稿之前,请检查收件人地址是否为自己。 如果 TO 是自己,则创建回复所有草稿而不是回复草稿 否则创建回复草稿。

    if(message.getTo() === Session.getEffectiveUser().getEmail())
    

    这是您可以检查的方式。

    还有另一种方法,您可以遍历所有电子邮件并从外部人员那里挑选最新的邮件并为其创建回复草稿。

    var mssgs = message.getThread().getMessages();
    

    【讨论】:

    • 通过使用replyAll,“to”字段仍设置为“me”地址,但添加了带有邮件收件人的“cc”。在第二种情况下,它只适用于有传入邮件的线程。如果只有现有的邮件是由用户发送的,则不可能这样做。
    • 感谢 cmets。我已经考虑并尝试了这两种方法,最终选择了 replyAll 选项。
    猜你喜欢
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 2014-12-12
    • 2018-02-19
    • 2010-10-24
    • 1970-01-01
    相关资源
    最近更新 更多