-
Notifications
You must be signed in to change notification settings - Fork 42
/
send_with_cc_sugar.js
60 lines (57 loc) · 1.43 KB
/
send_with_cc_sugar.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
'use strict';
var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, transmission = {
recipients: [
{
address: {
email: 'original.recipient@example.com',
name: 'Original Recipient'
},
substitution_data: {
recipient_type: 'Original'
}
},
],
cc: [
{
address: {
email: 'cc.recipient@example.com',
name: 'Carbon Copy Recipient',
},
substitution_data: {
recipient_type: 'CC'
}
}
],
content: {
from: {
name: 'Node CC Test',
email: 'from@example.com'
},
subject: 'Example email using cc',
text: 'An example email using cc with SparkPost to the {{recipient_type}} recipient.',
html: '<p>An example email using cc with SparkPost to the {{recipient_type}} recipient.</p>'
}
};
// Promise
client.transmissions.send(transmission)
.then(data => {
console.log('Congrats! You sent an email with cc using SparkPost!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});
// Callback
client.transmissions.send(transmission, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Congrats! You sent an email with cc using SparkPost!');
console.log(data);
}
});