Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Created November 27, 2014 01:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/96358f56ad8f142c5374 to your computer and use it in GitHub Desktop.
Save ryuheechul/96358f56ad8f142c5374 to your computer and use it in GitHub Desktop.
Alternative for parse.com’s cloud module Mandrill.
var mandrillApiKey;
var path = 'https://mandrillapp.com/api/1.0/messages/';
exports.initialize = function(apiKey) {
mandrillApiKey = apiKey;
};
exports.sendMail = function(params, options){
callMandrill('send.json', params, options);
};
exports.sendTemplate = function(params, options) {
callMandrill('send-template.json', params, options);
};
function callMandrill(url, params, options) {
Parse.Cloud.httpRequest({
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
url: path + url,
body: (function(){
params.key = mandrillApiKey;
return params;
})(),
},options);
}
@ryuheechul
Copy link
Author

Why do we need alternative?

UTF-8 characters such as Korean and Chinese are not sent through Parse’s Mandril cloud module.
So I just simply added 'charset=utf-8’ in HTTP header when using Mandril’s API.

Usage

// var Mandrill = require(“mandrill");
var Mandrill = require("[YOUR_PATH]/mandrill-utf-8.js"); // just add this line instead above line
Mandrill.initialize("vquEF_qDNFPIqSTl_dOMXw");
Mandrill.sendEmail({/*params*/},{/*options*/});
Mandrill.sendTemplate({/*params*/},{/*options*/});

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