-
Notifications
You must be signed in to change notification settings - Fork 4
/
bulk_send_with_merge_data.rb
63 lines (50 loc) · 2.47 KB
/
bulk_send_with_merge_data.rb
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
require_relative "../../lib/socketlabs-injectionapi.rb"
require "json"
class BulkSendWithMergeData
include SocketLabs::InjectionApi
include SocketLabs::InjectionApi::Core
include SocketLabs::InjectionApi::Message
def get_message
message = BulkMessage.new
message.subject = "Sending A Test Message With Merge Data"
message.html_body = "<html>" +
" <head><title>Sending A Test Message With Merge Data</title></head>" +
" <body>" +
" <h1>Sending A Complex Test Message</h1>" +
" <h2>Global Merge Data</h2>" +
" <p>Motto = <b>%%Motto%%</b></p>" +
" <h2>Per Recipient Merge Data</h2>" +
" <p>" +
" EyeColor = %%EyeColor%%<br/>" +
" HairColor = %%HairColor%%" +
" </p>" +
" </body>" +
"</html>"
message.plain_text_body = "Sending A Test Message With Merge Data" +
" Merged Data" +
" Motto = %%Motto%%" +
" " +
" Example of Merge Usage" +
" EyeColor = %%EyeColor%%" +
" HairColor = %%HairColor%%"
message.from_email_address = EmailAddress.new("from@example.com")
# Add some global merge-data (These will be applied to all Recipients
# unless specifically overridden by Recipient level merge-data)
message.add_global_merge_data("EyeColor", "{ not set }")
message.add_global_merge_data("HairColor", "{ not set }")
message.add_global_merge_data("Motto", "When hitting the Inbox matters!")
# Add recipients with merge data
recipient = BulkRecipient.new("recipient1@example.com")
recipient.add_merge_data("EyeColor", "Blue")
recipient.add_merge_data("HairColor", "Blond")
message.add_to_recipient(recipient)
recipient = BulkRecipient.new("recipient2@example.com", { :friendly_name => "Recipient #2" })
recipient.add_merge_data("EyeColor", "Green")
message.add_to_recipient(recipient)
recipient = BulkRecipient.new("recipient3@example.com")
recipient.add_merge_data("HairColor", "Brown")
message.add_to_recipient(recipient)
message.add_to_recipient(BulkRecipient.new("recipient4@example.com", { :friendly_name => "Recipient #4"}))
message
end
end