-
Notifications
You must be signed in to change notification settings - Fork 19
/
mandrill.js
55 lines (47 loc) · 1.7 KB
/
mandrill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Meteor.Mandrill = {
config: function (options) {
var host, key, port, username;
username = options["username"];
key = options["key"];
host = "smtp.mandrillapp.com";
port = "587";
process.env.MAIL_URL = "smtp://" + username + ":" + key + "@" + host + ":" + port + "/";
},
send: function (options) {
Email.send(options);
},
sendTemplate: function (options, callback) {
var url = "https://mandrillapp.com/api/1.0/messages/send-template.json",
result;
options = {
"data": {
"key": options.key,
"template_name": options.template_name,
"template_content": options.template_content,
"message": options.message,
"headers": [{
"Content-Type": "application/json"
}]
}
};
try {
// if a callback is provided do an asynch call
if (!! callback) HTTP.post(url, options, callback);
// if no callback do a synchronous call and store the result
else result = HTTP.post(url, options);
} catch (e) {
console.log(e.stack);
}
},
renderTemplate: function (options, callback) {
var url = "https://mandrillapp.com/api/1.0/templates/render.json";
try {
// if a callback is provided do an asynch call
if (!! callback) HTTP.post(url, { data: options }, callback);
// if no callback do a synchronous call and return the result
else return HTTP.post(url, { data: options });
} catch (e) {
console.log(e.stack);
}
}
};