I try to automatically attach a file from my Google Drive (so ideally with the file id) in my Gmail draft created with Google Apps Script and GMail API. I use the syntax below. Can I do that easily? Creating the draft works great by the way.
Thanks! Chris
function createDraft() {
var forScope = GmailApp.getInboxUnreadCount(); // needed for auth scope
var htmlBody = 'Howzit';
var raw =
'Subject: Howzit\n' +
'To: aa@bb.cc\n' +
'Content-Type: text/html; charset=UTF-8\r\n' +
'\r\n' + htmlBody;
var draftBody = Utilities.base64Encode(raw, Utilities.Charset.UTF_8).replace(/\//g,'_').replace(/\+/g,'-');
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);
}