i want know if it's possible create draft mail using google apps script. , if yes, how possible ?
regards, sebastien
at point in time, there no way create new message appears in drafts
folder. functionality has been requested - see issue 985. if interested in receiving updates, visit , star issue.
edit: while still not natively supported in google apps script, can create drafts using gmail api, using getoauthtoken()
authenticate (introduced feb 2014). drafts support added api in june 2014, , example of use gas shown in comment 29 of above issue. code reproduced here convenience:
function createdraft() { var forscope = gmailapp.getinboxunreadcount(); // needed auth scope var raw = 'subject: testing draft\n' + //'to: test@test.com\n' + 'content-type: multipart/alternative; boundary=1234567890123456789012345678\n' + 'testing draft msg\n' + '--1234567890123456789012345678--\n'; var draftbody = utilities.base64encode(raw); 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); logger.log(resp.getcontenttext()); /* * sample resp: { * "id": "r3322255254535847929", * "message": { * "id": "146d6ec68eb36de8", * "threadid": "146d6ec68eb36de8", * "labelids": [ "draft" ] * } * } */ }
Comments
Post a Comment