I created a script (via Google App Script) that simplifies replying to emails. The script replaces the following manual steps: (while in an email)
- Forward the email.
- Copy the "To" addresses from the original email.
- Paste the "To" addresses into the forwarded email.
- Copy the "CC" addresses from the original email.
- Paste the "CC" addresses into the forwarded email.
- Add a short text.
- The email is then saved in the "Drafts" folder.
Code:
function REP() {
// Activate temporary Gmail scopes, in this case to allow
// the add-on to read message metadata and content.
var accessToken = e.gmail.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
// Read message metadata and content. This requires the Gmail scope
// .addons.current.message.readonly.
var d1 = CardService.newDivider();
var textToIn2 = CardService.newTextInput()
.setFieldName("textTO2")
.setMultiline(true);
var composeAction = CardService.newAction()
.setFunctionName('createReplyDraft');
var composeButton = CardService.newTextButton()
.setText('FK3')
.setComposeAction(composeAction, CardService.ComposedEmailType.REPLY_AS_DRAFT);
var cardSection1 = CardService.newCardSection()
//.setHeader('InFFo')
//.setCollapsible(false)
//.setNumUncollapsibleWidgets(0)
.addWidget(textToIn2)
.addWidget(d1)
.addWidget(composeButton);
var card = CardService.newCardBuilder()
.addSection(cardSection1)
.build();
return card;
}
function createReplyDraft(e) {
// Activate temporary Gmail scopes, in this case to allow
// a reply to be drafted.
//var accessToken = e.gmail.accessToken;
//GmailApp.setCurrentMessageAccessToken(accessToken);
// Creates a draft reply.
var messageId = e.gmail.messageId;
var message = GmailApp.getMessageById(messageId);
var mto = message.getTo();
//Logger.log("mto= " + mto);
var mfrom = message.getFrom();
//Logger.log("mfrom= " + mfrom);
var mtoCC0 = message.getCc();
//Logger.log("mtoCC0= " +mtoCC0);
var mSub = message.getSubject();
//Logger.log("mSub= " + mSub);
var mBody = message.getBody();
//var mAttach = m.getAttachments();
var mAttach = message.getAttachments();
// delete all spaces
//var NmtoCC = mtoCC0.replace(/ /g, '');
//var adressArr = NmtoCC.split(",");
var f = "some e- mail adresss @aaaaaa"; //looking adress
var Findf = false;
if (mtoCC0.indexOf(f) < 0) { Findf = true; }
//Logger.log("Findf= " + Findf);
if (Findf) { mtoCC0= mtoCC0 + " ," + f ;}
//Logger.log("2. mtoCC0= " +mtoCC0);
var textget = e.formInputs.textTO2;
//e.formInputs.textTO
//Logger.log("TEXT= " + textget);
mBody = "<br>" + textget + "<br><br><br>" + mBody;
var draft = message.createDraftReply('', { cc: mtoCC0,
htmlBody: mBody,
attachments: mAttach,
replyTo: mfrom,
subject: mSub
}
);
// 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();
}
The problem is that my coworkers receive my replies as a new email, rather than as a continuation of the thread. What should I change to ensure they receive it as a continuation of the thread?
appsscript.json
{
"oauthScopes": [
".container.ui",
".addons.execute",
".addons.current.message.metadata",
".modify",
".addons.current.actionpose",
".locale"
],
"gmail": {
"name": "FallowK",
"logoUrl": ".png",
"primaryColor": "#07b4ed",
"secondaryColor": "#ed7207",
"contextualTriggers": [
{
"unconditional": {},
"onTriggerFunction": "REP"
}
]
},
"timeZone": "Europe/Warsaw",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
I created a script (via Google App Script) that simplifies replying to emails. The script replaces the following manual steps: (while in an email)
- Forward the email.
- Copy the "To" addresses from the original email.
- Paste the "To" addresses into the forwarded email.
- Copy the "CC" addresses from the original email.
- Paste the "CC" addresses into the forwarded email.
- Add a short text.
- The email is then saved in the "Drafts" folder.
Code:
function REP() {
// Activate temporary Gmail scopes, in this case to allow
// the add-on to read message metadata and content.
var accessToken = e.gmail.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
// Read message metadata and content. This requires the Gmail scope
// https://www.googleapis/auth/gmail.addons.current.message.readonly.
var d1 = CardService.newDivider();
var textToIn2 = CardService.newTextInput()
.setFieldName("textTO2")
.setMultiline(true);
var composeAction = CardService.newAction()
.setFunctionName('createReplyDraft');
var composeButton = CardService.newTextButton()
.setText('FK3')
.setComposeAction(composeAction, CardService.ComposedEmailType.REPLY_AS_DRAFT);
var cardSection1 = CardService.newCardSection()
//.setHeader('InFFo')
//.setCollapsible(false)
//.setNumUncollapsibleWidgets(0)
.addWidget(textToIn2)
.addWidget(d1)
.addWidget(composeButton);
var card = CardService.newCardBuilder()
.addSection(cardSection1)
.build();
return card;
}
function createReplyDraft(e) {
// Activate temporary Gmail scopes, in this case to allow
// a reply to be drafted.
//var accessToken = e.gmail.accessToken;
//GmailApp.setCurrentMessageAccessToken(accessToken);
// Creates a draft reply.
var messageId = e.gmail.messageId;
var message = GmailApp.getMessageById(messageId);
var mto = message.getTo();
//Logger.log("mto= " + mto);
var mfrom = message.getFrom();
//Logger.log("mfrom= " + mfrom);
var mtoCC0 = message.getCc();
//Logger.log("mtoCC0= " +mtoCC0);
var mSub = message.getSubject();
//Logger.log("mSub= " + mSub);
var mBody = message.getBody();
//var mAttach = m.getAttachments();
var mAttach = message.getAttachments();
// delete all spaces
//var NmtoCC = mtoCC0.replace(/ /g, '');
//var adressArr = NmtoCC.split(",");
var f = "some e- mail adresss @aaaaaa"; //looking adress
var Findf = false;
if (mtoCC0.indexOf(f) < 0) { Findf = true; }
//Logger.log("Findf= " + Findf);
if (Findf) { mtoCC0= mtoCC0 + " ," + f ;}
//Logger.log("2. mtoCC0= " +mtoCC0);
var textget = e.formInputs.textTO2;
//e.formInputs.textTO
//Logger.log("TEXT= " + textget);
mBody = "<br>" + textget + "<br><br><br>" + mBody;
var draft = message.createDraftReply('', { cc: mtoCC0,
htmlBody: mBody,
attachments: mAttach,
replyTo: mfrom,
subject: mSub
}
);
// 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();
}
The problem is that my coworkers receive my replies as a new email, rather than as a continuation of the thread. What should I change to ensure they receive it as a continuation of the thread?
appsscript.json
{
"oauthScopes": [
"https://www.googleapis/auth/script.container.ui",
"https://www.googleapis/auth/gmail.addons.execute",
"https://www.googleapis/auth/gmail.addons.current.message.metadata",
"https://www.googleapis/auth/gmail.modify",
"https://www.googleapis/auth/gmail.addons.current.actionpose",
"https://www.googleapis/auth/script.locale"
],
"gmail": {
"name": "FallowK",
"logoUrl": "https://www.gstatic/images/icons/material/system/1x/label_googblue_24dp.png",
"primaryColor": "#07b4ed",
"secondaryColor": "#ed7207",
"contextualTriggers": [
{
"unconditional": {},
"onTriggerFunction": "REP"
}
]
},
"timeZone": "Europe/Warsaw",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
Share
Improve this question
edited Jan 19 at 19:32
Wicket
38.5k9 gold badges78 silver badges193 bronze badges
asked Jan 18 at 14:46
Chora PocztaChora Poczta
11 bronze badge
1
|
1 Answer
Reset to default -1What is the e event in the createReplyDraft(e) function? How do you activated this function? What do you have in your manifest file?
If you activate this function using a contextual trigger, then from the e event you can extract information about the current message and thread, which you can use to reply.
For example:
var messageId = e.messageMetadata.messageId;
var threadId = GmailApp.getMessageById(messageId).getThread().getId();
Read Make email more actionable with Google Workspace Add-ons, it will help you.
problem
where thereplies
area new email, rather than as a continuation of the thread.
Kindly share a minimal, reproducible example—no sensitive data with your desired output—that the community can use to replicate and see what you'd like to do. – Saddles Commented Jan 20 at 18:41