-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathsend_all_fields.js
73 lines (70 loc) · 1.94 KB
/
send_all_fields.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
'use strict';
var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, transmission = {
options: {
open_tracking: true,
click_tracking: true
},
campaign_id: 'christmas_campaign',
metadata: {
user_type: 'students'
},
substitution_data: {
sender: 'Big Store Team'
},
recipients: [
{
address: {
email: '[email protected]',
name: 'Wilma Flintstone'
},
tags: [
'greeting',
'prehistoric',
'fred',
'flintstone'
],
metadata: {
place: 'Bedrock'
},
substitution_data: {
customer_type: 'Platinum'
}
}
],
content: {
from: {
name: 'Fred Flintstone',
email: '[email protected]'
},
subject: 'Big Christmas savings!',
reply_to: 'Christmas Sales <[email protected]>',
headers: {
'X-Customer-Campaign-ID': 'christmas_campaign'
},
text: 'Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}',
html: '<p>Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n</p><p>Hurry, this offer is only to {{customer_type}}\n</p><p>{{sender}}</p>'
}
};
// Promise
client.transmissions.send(transmission)
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});
// Callback
client.transmissions.send(tranmission, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Congrats you can use our client library!');
console.log(data);
}
});