-
Notifications
You must be signed in to change notification settings - Fork 5
/
bulk_send_with_ascii_charset_merge_data.py
61 lines (44 loc) · 2.02 KB
/
bulk_send_with_ascii_charset_merge_data.py
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
# -*- coding: utf-8 -*-
import json
import os
from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
BulkMessage, BulkRecipient, EmailAddress
# build the message
message = BulkMessage()
message.subject = "Sending A Test Message With ASCII Charset Merge Data"
# Set HTML and plain text body, both of which use UTF-8 characters
# Build the Content (Note the %% symbols used to denote the data to be merged)
message.html_body = "<html>" \
" <body>" \
" <h1>Sending A Test Message With ASCII Charset Merge Data</h1>" \
" <h2>Merge Data</h2>" \
" <p>Complete? = %%Complete%%</p>" \
" </body>" \
"</html>"
message.plain_text_body = "Sending A Test Message With ASCII Charset Merge Data" \
" Merged Data" \
" Complete? = %%Complete%%"
message.from_email_address = EmailAddress("[email protected]")
# set the charset
message.charset = "ASCII"
message.add_global_merge_data("Complete", "{ no response }")
# Add recipients with merge data that contains UTF-8 characters
recipient1 = BulkRecipient("[email protected]")
recipient1.add_merge_data("Complete", "✘")
message.add_to_recipient(recipient1)
recipient2 = BulkRecipient("[email protected]", "Recipient #2")
recipient2.add_merge_data("Complete", "✔")
message.add_to_recipient(recipient2)
recipient3 = BulkRecipient("[email protected]")
recipient3.add_merge_data("Complete", "✘")
message.add_to_recipient(recipient3)
message.add_to_recipient(BulkRecipient("[email protected]", "Recipient #4"))
# get credentials from environment variables
server_id = int(os.environ.get('SOCKETLABS_SERVER_ID'))
api_key = os.environ.get('SOCKETLABS_INJECTION_API_KEY')
# create the client
client = SocketLabsClient(server_id, api_key)
# send the message
response = client.send(message)
print(json.dumps(response.to_json(), indent=2))