forked from SparkPost/node-sparkpost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_transmission_all_fields.js
65 lines (62 loc) · 1.74 KB
/
send_transmission_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
"use strict";
var key = "YOURAPIKEY"
, SparkPost = require("sparkpost")
, client = new SparkPost(key);
var reqOpts = {
transmissionBody: {
options: {
open_tracking: true,
click_tracking: true
},
campaign_id: "christmas_campaign",
return_path: "[email protected]",
metadata: {
user_type: "students"
},
substitution_data: {
sender: "Big Store Team"
},
recipients: [
{
return_path: "[email protected]",
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 {{user_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 {{user_type}}\n</p><p>{{sender}}</p>"
}
}
};
client.transmissions.send(reqOpts, function(err, res) {
if (err) {
console.log(err);
} else {
console.log(res.body);
console.log("Congrats you can use our SDK!");
}
});