-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbasic_send_complex.rb
More file actions
234 lines (188 loc) · 9.35 KB
/
basic_send_complex.rb
File metadata and controls
234 lines (188 loc) · 9.35 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
require_relative "../../lib/socketlabs-injectionapi.rb"
require "json"
class BasicSendComplex
include SocketLabs::InjectionApi
include SocketLabs::InjectionApi::Core
include SocketLabs::InjectionApi::Message
def get_message
message = BasicMessage.new
message.subject = "Sending A Complex Test Message (Basic Send))"
message.html_body = "<html><body><h1>Sending A Complex Test Message</h1><p>This is the Html Body of my message.</p><h2>UTF16 Characters:</h2><p>例 (example)</p><h2>Embedded Image:</h2><p><img src=\"cid:bus\" /></p></body></html>"
message.plain_text_body = "This is the Plain Text Body of my message."
message.amp_body = "<!doctype html>" +
"<html amp4email>" +
" <head>" +
" <meta charset=\"utf-8\">" +
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
" <style amp-custom>" +
" h1 {" +
" margin: 1rem;" +
" }" +
" </style>" +
" </head>" +
" <body>" +
" <h1>This is the AMP Html Body of my message</h1>" +
" </body>" +
"</html>"
message.message_id = "ComplexExample"
message.mailing_id = "BasicSend"
message.charset = "UTF16"
message.from_email_address = EmailAddress.new("from@example.com")
message.reply_to_email_address = EmailAddress.new("replyto@example.com")
# Adding To Recipients
# --------
# Add Email Addresses using an Array
email_addresses = Array.new
# String in array
email_addresses.push("recipient1@example.com")
# EmailAddress object in array
email_addresses.push(EmailAddress.new("recipient2@example.com"))
email_addresses.push(EmailAddress.new("recipient3@example.com", "Recipient #3"))
# hash in array
email_addresses.push({:email_address => "recipient4@example.com"})
email_addresses.push({:email_address => "recipient5@example.com", :friendly_name =>"Recipient #5"})
message.to_email_address = email_addresses
# Add Email Addresses directly to the Array
# String
message.to_email_address.push("recipient11@example.com")
# EmailAddress object
message.to_email_address.push(EmailAddress.new("recipient12@example.com"))
message.to_email_address.push(EmailAddress.new("recipient13@example.com", "Recipient #13"))
# hash in array
message.to_email_address.push({:email_address => "recipient14@example.com"})
message.to_email_address.push({:email_address => "recipient15@example.com", :friendly_name =>"Recipient #15"})
# Add Email Addresses using the add_to_email_address function
# String
message.add_to_email_address("recipient21@example.com")
message.add_to_email_address("recipient22@example.com", "Recipient #22")
# EmailAddress object
message.add_to_email_address(EmailAddress.new("recipient23@example.com"))
message.add_to_email_address(EmailAddress.new("recipient24@example.com", "Recipient #24"))
# hash
message.add_to_email_address({:email_address => "recipient25@example.com"})
message.add_to_email_address({:email_address => "recipient26@example.com", :friendly_name =>"Recipient #26"})
# adding Array
# Add Email Addresses using an Array
email_addresses = Array.new
# String in array
email_addresses.push("recipient31@example.com")
# EmailAddress object in array
email_addresses.push(EmailAddress.new("recipient32@example.com"))
email_addresses.push(EmailAddress.new("recipient33@example.com", "Recipient #33"))
# hash in array
email_addresses.push({:email_address => "recipient34@example.com"})
email_addresses.push({:email_address => "recipient35@example.com", :friendly_name =>"Recipient #35"})
message.add_to_email_address(email_addresses)
# Adding CC Recipients
# --------
# Add Email Addresses using an Array
email_addresses = Array.new
email_addresses.push("cc_recipient1@example.com")
email_addresses.push(EmailAddress.new("cc_recipient2@example.com"))
email_addresses.push({:email_address => "cc_recipient3@example.com", :friendly_name =>"CC Recipient #3"})
message.cc_email_address = email_addresses
# Add Email Addresses directly to the Array
message.cc_email_address.push("cc_recipient4@example.com")
message.cc_email_address.push(EmailAddress.new("cc_recipient5@example.com", "CC Recipient #5"))
message.cc_email_address.push({:email_address => "cc_recipient6@example.com", :friendly_name =>"CC Recipient #6"})
# Add Email Addresses using the add_to_email_address function
message.add_cc_email_address("cc_recipient7@example.com", "CC Recipient #7")
message.add_cc_email_address(EmailAddress.new("cc_recipient8@example.com"))
message.add_cc_email_address({:email_address => "cc_recipient9@example.com", :friendly_name =>"CC Recipient #9"})
# Add Email Addresses using an Array
email_addresses = Array.new
email_addresses.push("cc_recipient10@example.com")
email_addresses.push(EmailAddress.new("cc_recipient11@example.com", "CC Recipient #11"))
email_addresses.push({:email_address => "cc_recipient12@example.com", :friendly_name =>"CC Recipient #12"})
message.add_cc_email_address(email_addresses)
# Adding BCC Recipients
# --------
# Add Email Addresses using an Array
email_addresses = Array.new
email_addresses.push("bcc_recipient1@example.com")
email_addresses.push(EmailAddress.new("bcc_recipient2@example.com"))
email_addresses.push({:email_address => "bcc_recipient3@example.com", :friendly_name =>"BCC Recipient #3"})
message.bcc_email_address = email_addresses
# Add Email Addresses directly to the Array
message.bcc_email_address.push("bcc_recipient4@example.com")
message.bcc_email_address.push(EmailAddress.new("bcc_recipient5@example.com", "BCC Recipient #5"))
message.bcc_email_address.push({:email_address => "bcc_recipient6@example.com", :friendly_name =>"BCC Recipient #6"})
# Add Email Addresses using the add_to_email_address function
message.add_bcc_email_address("bcc_recipient7@example.com", "BCC Recipient #7")
message.add_bcc_email_address(EmailAddress.new("bcc_recipient8@example.com"))
message.add_bcc_email_address({:email_address => "bcc_recipient9@example.com", :friendly_name =>"BCC Recipient #9"})
# Add Email Addresses using an Array
email_addresses = Array.new
email_addresses.push("bcc_recipient10@example.com")
email_addresses.push(EmailAddress.new("bcc_recipient11@example.com", "BCC Recipient #11"))
email_addresses.push({:email_address => "bcc_recipient12@example.com", :friendly_name =>"BCC Recipient #12"})
message.add_bcc_email_address(email_addresses)
# Adding Custom Headers
# --------
# Add CustomHeader using a list
headers = Array.new
headers.push(CustomHeader.new("example-type", "basic-send-complex-example"))
headers.push(CustomHeader.new("message-contains", "attachments, headers"))
message.custom_headers = headers
# Add CustomHeader directly to the list
message.custom_headers.push(CustomHeader.new("message-has-attachments", "true"))
# Add CustomHeader using the add_custom_header function
message.add_custom_header("testMessageHeader", "I am a message header")
message.add_custom_header(CustomHeader.new("testMessageHeader2", "I am another message header"))
# Adding Attachments
attachment1 = Attachment.new(
name:"bus",
file_path:"../img/bus.png",
mime_type:"image/png"
)
message.attachments.push(attachment1)
# Add Attachment using the add_attachment function
attachment2 = Attachment.new(
name:"bus2",
file_path:"../img/bus.png",
mime_type:"image/png"
)
attachment2.content_id = "bus"
message.add_attachment(attachment2)
# Add Attachment a filePath {string} to the array
message.add_attachment(Attachment.new(file_path:"../html/SampleEmail.html"))
# Add Attachment using bytes of the file
file_path = "../img/bus.png"
file = File.open(file_path, "rb")
data = Base64.encode64(file.read)
attachment4 = Attachment.new(
name: "yellow-bus.png",
mime_type: "image/png",
content: data
)
# Add CustomHeaders to Attachment
attachment4.custom_headers.push(CustomHeader.new("Color", "Yellow"))
attachment4.add_custom_header("Place", "Beach")
message.add_attachment(attachment4)
# Adding Metadata
# --------
# Add Metadata using a list
metadata = Array.new
metadata.push(Metadata.new("x-mycustommetadata", "I am custom metadata"))
metadata.push(Metadata.new("x-internalid", "123"))
message.metadata = metadata
# Add Metadata directly to the list
message.metadata.push(Metadata.new("x-mycustommetadata", "I am custom metadata"))
# Add Metadata using the add_metadata function
message.add_metadata("x-mycustommetadata2", "Custom metadata")
message.add_metadata(Metadata.new("x-externalid", "456"))
# Adding Tags
# --------
# Add Tags using a list
tags = Array.new
tags.push("example-type:basic-send-complex")
message.tags = tags
# Add Tags directly to the list
message.tags.push("has-attachments:true")
# Add Metadata using the add_metadata function
message.add_tag("I am a test message")
message.add_tag("ruby-Example")
message
end
end