我在 这里参考官方指南
创建回复草稿。
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()
(草稿)我→我
如何创建具有正确收件人的回复草稿?