I know how to send a Gmail draft with:
var draft = GmailApp.getDrafts()[0];
var msg = draft.send();
and how to modify the draft with update
:
draft.update("[email protected]", "current time", "The time hello")
But how to modify the subject only and not the content, not the attachments (if any), not the recipient?
If my understanding is correct, how about this sample script? I think that there are several answers. So please think of this as just one of them.
In this sample script, I used Class GmailApp and Gmail API. The flow of script is as follows.
Utilities.base64EncodeWebSafe()
.By this flow, only subject can be updated.
Before you run this script, please enable Gmail API at Advanced Google Services and API console.
function updateDraftmail() {
var newSubject = "new subject"; // Please set new subject.
var userId = "me"; // Please set userId.
var draft = GmailApp.getDrafts()[0]; // Retrieve a draft.
var raw = draft.getMessage().getRawContent();
var newRaw = raw.replace(/Subject: \w.+/, "Subject: " + newSubject);
var newRawB64 = Utilities.base64EncodeWebSafe(newRaw, Utilities.Charset.UTF_8);
Gmail.Users.Drafts.update({message: {raw: newRawB64}}, userId, draft.getId());
}
If I misunderstood your question and this was not what you want, I apologize.