Created
March 26, 2016 18:08
-
-
Save shubs/b8b5ae74928777e6c441 to your computer and use it in GitHub Desktop.
How to send an email via the Pebble using the Mailjet API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Welcome to Pebble.js! | |
* | |
* This is where you write your app. | |
*/ | |
var UI = require('ui'); | |
var Vector2 = require('vector2'); | |
var ajax = require('ajax'); | |
var main = new UI.Card({ | |
title: 'Pebble.js', | |
icon: 'images/menu_icon.png', | |
subtitle: 'Hello World!', | |
body: 'Press any button.', | |
subtitleColor: 'indigo', // Named colors | |
bodyColor: '#9a0036' // Hex colors | |
}); | |
main.show(); | |
main.on('click', 'up', function(e) { | |
var menu = new UI.Menu({ | |
sections: [{ | |
items: [{ | |
title: 'Pebble.js', | |
icon: 'images/menu_icon.png', | |
subtitle: 'Can do Menus' | |
}, { | |
title: 'Second Item', | |
subtitle: 'Subtitle Text' | |
}] | |
}] | |
}); | |
menu.on('select', function(e) { | |
console.log('Selected item #' + e.itemIndex + ' of section #' + e.sectionIndex); | |
console.log('The item is titled "' + e.item.title + '"'); | |
}); | |
menu.show(); | |
}); | |
main.on('click', 'select', function(e) { | |
var wind = new UI.Window({ | |
fullscreen: true, | |
}); | |
var textfield = new UI.Text({ | |
position: new Vector2(0, 65), | |
size: new Vector2(144, 30), | |
font: 'gothic-24-bold', | |
text: 'Text Anywhere!', | |
textAlign: 'center' | |
}); | |
wind.add(textfield); | |
wind.show(); | |
}); | |
main.on('click', 'down', function(e) { | |
var card = new UI.Card(); | |
card.title('A Card'); | |
card.subtitle('Is a Window'); | |
card.body('The simplest window type in Pebble.js.'); | |
card.show(); | |
// Here is where starts the mailjet API usage | |
// acording to http://dev.mailjet.com/guides/?shell#sending-a-basic-email | |
ajax( | |
{ | |
url: 'http://APIJET:[email protected]/v3/send', | |
method: 'post', | |
type: 'json', | |
data: { | |
"FromEmail":"[email protected]", | |
"FromName":"FIXME", | |
"Subject":"FIXME", | |
"Text-part":"Dear passenger, welcome to Mailjet! May the delivery force be with you!", | |
"Html-part":"<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!", | |
"Recipients":[{"Email":"[email protected]"}] | |
}, | |
crossDomain: true | |
}, | |
function(result) { | |
console.log('Success and Result is: ' + result); | |
}, | |
function(error) { | |
console.log('The ajax request failed: ' + error); | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment