Skip to content

Instantly share code, notes, and snippets.

@MauricioMoraes
Last active August 29, 2015 14:25
Show Gist options
  • Save MauricioMoraes/145ce3f36fdb025e0300 to your computer and use it in GitHub Desktop.
Save MauricioMoraes/145ce3f36fdb025e0300 to your computer and use it in GitHub Desktop.
Google Apps Script Function to get the first gmail draft from your account and output its attributes.
function getFirstGmailDraftAttributes() {
var draftThreads = GmailApp.search("in:drafts", 0, 1);
if (draftThreads.length === 0) {
Browser.msgBox("No drafts found.");
return
}
var draft = draftThreads[0].getMessages()[0];
var draftAttributes = {
id: draft.getId(),
subject: draft.getSubject(),
to: draft.getTo(),
cc: draft.getCc(),
bcc: draft.getBcc(),
body: draft.getBody(),
attachments: draft.getAttachments()
}
return draftAttributes;
}
@MauricioMoraes
Copy link
Author

Example: Showing the subject for the first draft in your gmail account.

var draftSubject = getFirstGmailDraftAttributes().subject;
Browser.msgBox(draftSubject);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment