-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmandrill.js
95 lines (91 loc) · 3.03 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var mandrill = require('mandrill-api/mandrill');
var mandrill_client = new mandrill.Mandrill('HwSNMGOM1BPbwp5gr0QSuw');
var fs = require("fs");
function sendEmail (emailAddress, mongoid) {
var email = fs.readFileSync('views/email.html').toString();
var report = fs.readFileSync('reports/'+mongoid+".pdf");
var base64str = Buffer(report).toString('base64');
var message = {
"html": email,
"text": "This is your App report from Keyword KING",
"subject": "App Report from Keyword KING",
"from_email": "[email protected]",
"from_name": "Keyword KING",
"to": [{
"email": emailAddress,
"name": "Keyword KING",
"type": "to"
}],
"headers": {
"Reply-To": "[email protected]"
},
"important": null,
"track_opens": null,
"track_clicks": null,
"auto_text": null,
"auto_html": null,
"inline_css": null,
"url_strip_qs": null,
"preserve_recipients": null,
"view_content_link": null,
"bcc_address": "",
"tracking_domain": null,
"signing_domain": null,
"return_path_domain": null,
"merge": true,
"merge_language": "mailchimp",
"global_merge_vars": [{
"name": "merge1",
"content": "merge1 content"
}],
"merge_vars": [{
"rcpt": "[email protected]",
"vars": [{
"name": "merge2",
"content": "merge2 content"
}]
}],
"tags": [
"password-resets"
],
// "subaccount": "customer-123",
"google_analytics_domains": [
"example.com"
],
"google_analytics_campaign": "[email protected]",
"metadata": {
"website": "www.example.com"
},
"recipient_metadata": [{
"rcpt": "[email protected]",
"values": {
"user_id": 123456
}
}],
"attachments": [{
"type": "application/pdf",
"name": "Keyword KING App Report.pdf",
"content": base64str
}],
// "images": [{
// "type": "image/png",
// "name": "article1.png",
// "content": "3223F34F3CSDSDVSDV"
// }]
};
var async = false;
var ip_pool = "Main Pool";
var send_at = '';
mandrill_client.messages.send({"message": message, "async": async, "ip_pool": ip_pool, "send_at": send_at}, function(result) {
console.log('Email sent ----', result);
fs.unlink('reports/'+mongoid+".pdf", function (err) {
if (err) throw err;
console.log('successfully deleted report');
});
}, function(e) {
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
});
}
module.exports = {
sendEmail: sendEmail
};