Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Created May 20, 2015 15:52
Show Gist options
  • Select an option

  • Save oshliaer/6f78d7c777787428638b to your computer and use it in GitHub Desktop.

Select an option

Save oshliaer/6f78d7c777787428638b to your computer and use it in GitHub Desktop.
Sends the specified message to the recipients in the To, Cc, and Bcc headers. #gapi #snippet #gmail [not /upload]
function sendMail() {
var email = [
'From: John Doe <jdoe@machine.example> ',
'To: Mary Smith <mary@example.net> ',
'Subject: Saying Hello ',
'Date: Fri, 21 Nov 1997 09:55:06 -0600 ',
'Message-ID: <1234@local.machine.example>',
'',
'This is a message just to say hello. So, "Hello".'
].join('\r\n');
var request = gapi.client.request({
'path' : '/gmail/v1/users/me/messages/send',
'method' : 'POST',
'body' : {
'raw' : btoa(email).replace(/\+/g, '-').replace(/\//g, '_')
}
}).then(opt_onFulfilled, opt_onRejected);
}
function opt_onRejected(e) {
console.log(e);
}
function opt_onFulfilled(e) {
console.log(e);
}
@oshliaer
Copy link
Copy Markdown
Author

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