Skip to content

Commit b23f605

Browse files
committed
Adding AMP tests to examples program
1 parent 055df64 commit b23f605

File tree

4 files changed

+159
-3
lines changed

4 files changed

+159
-3
lines changed

python-examples/basic/basic_send_complex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@
2121
"</body></html>"
2222
message.plain_text_body = "This is the Plain Text Body of my message."
2323

24+
# Setting AMP Body
25+
message.setAmpBody = "<!doctype html>" \
26+
"<html amp4email>" \
27+
" <head>" \
28+
" <meta charset=\"utf-8\">" \
29+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" \
30+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" \
31+
" <style amp-custom>" \
32+
" h1 {" \
33+
" margin: 1rem;" \
34+
" }" \
35+
" </style>" \
36+
" </head>" \
37+
" <body>" \
38+
" <h1>This is the AMP Html Body of my message</h1>" \
39+
" </body>" \
40+
"</html>"
41+
2442
message.from_email_address = EmailAddress("[email protected]")
2543
message.reply_to_email_address = EmailAddress("[email protected]")
2644

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
import os
3+
4+
from socketlabs.injectionapi import SocketLabsClient
5+
from socketlabs.injectionapi.message.__imports__ import \
6+
BasicMessage, EmailAddress
7+
8+
# For more information on AMP Html, visit the following link: amp.dev/documentation
9+
10+
# build the message
11+
message = BasicMessage()
12+
13+
message.subject = "Sending A Test Message (Basic Send)"
14+
15+
message.html_body = "<html><body>" \
16+
"<h1>This HTML will show if AMP is not supported on the receiving end of the email.</h1>" \
17+
"<p>This is the Html Body of my message.</p>" \
18+
"</body></html>"
19+
message.amp_body = "<!doctype html>" \
20+
"<html amp4email>" \
21+
"<head>" \
22+
" <meta charset=\"utf-8\">" \
23+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" \
24+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" \
25+
" <style amp-custom>" \
26+
" h1 {" \
27+
" margin: 1rem;" \
28+
" }" \
29+
" </style>" \
30+
"</head>" \
31+
"<body>" \
32+
" <h1>This is the AMP Html Body of my message</h1>" \
33+
"</body>" \
34+
"</html>"
35+
36+
message.from_email_address = EmailAddress("[email protected]")
37+
message.add_to_email_address("[email protected]")
38+
message.add_to_email_address("[email protected]", "Recipient #2")
39+
message.add_to_email_address(EmailAddress("[email protected]"))
40+
message.add_to_email_address(EmailAddress("[email protected]", "Recipient #4"))
41+
42+
43+
# get credentials from environment variables
44+
server_id = int(os.environ.get('SOCKETLABS_SERVER_ID'))
45+
api_key = os.environ.get('SOCKETLABS_INJECTION_API_KEY')
46+
47+
# create the client
48+
client = SocketLabsClient(server_id, api_key)
49+
50+
# send the message
51+
response = client.send(message)
52+
53+
print(json.dumps(response.to_json(), indent=2))

python-examples/bulk/bulk_send_complex.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
message.charset = "UTF-8"
1616

17-
message.subject = "Sending A Complex Test Message"
17+
message.subject = "Sending A Complex Bulk Test Message"
1818
message.html_body = "<html>" \
19-
" <head><title>Sending A Complex Test Message</title></head>" \
19+
" <head><title>Sending A Complex Bulk Test Message</title></head>" \
2020
" <body>" \
2121
" <h1>Sending A Complex Test Message</h1>" \
2222
" <h2>Merge Data</h2>" \
@@ -37,7 +37,7 @@
3737
" <p><img src='cid:bus' /></p>" \
3838
" </body>" \
3939
"</html>"
40-
message.plain_text_body = "Sending A Complex Test Message" \
40+
message.plain_text_body = "Sending A Complex Bulk Test Message" \
4141
" Merged Data" \
4242
" Motto = %%Motto%%" \
4343
" Birthday = %%Birthday%%" \
@@ -47,6 +47,37 @@
4747
" Example of Merge Usage" \
4848
" Our company motto is '%%Motto%%'." \
4949
" Your birthday is %%Birthday%% and you are %%Age%% years old."
50+
message.amp_body = "<!doctype html>"\
51+
"<html amp4email>" \
52+
"<head>"\
53+
"<title>Sending an AMP Test Message</title>"\
54+
" <meta charset=\"utf-8\">"\
55+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>"\
56+
" <style amp4email-boilerplate>body{visibility:hidden}</style>"\
57+
" <style amp-custom>"\
58+
" h1 {"\
59+
" margin: 1rem;"\
60+
" }"\
61+
" </style>"\
62+
"</head>"\
63+
"<body>"\
64+
" <h1>Sending An AMP Complex Test Message</h1>"\
65+
" <h2>Merge Data</h2>"\
66+
" <p>"\
67+
" Motto = <b>%%Motto%%</b> </br>"\
68+
" Birthday = <b>%%Birthday%%</b> </br>"\
69+
" Age = <b>%%Age%%</b> </br>"\
70+
" UpSell = <b>%%UpSell%%</b>"\
71+
" </p>"\
72+
" <h2>Example of Merge Usage</h2>"\
73+
" <p>"\
74+
" Our company motto is '<b>%%Motto%%</b>'. </br>"\
75+
" Your birthday is <b>%%Birthday%%</b> and you are <b>%%Age%%</b> years old."\
76+
" </p>"\
77+
" <h2>UTF-8 Characters:</h2>"\
78+
" <p>✔ - Check</p>"\
79+
" </body>"\
80+
" </html>"
5081

5182
message.from_email_address = EmailAddress("[email protected]", "FromMe")
5283
message.reply_to_email_address = EmailAddress("[email protected]")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import json
2+
import os
3+
4+
from socketlabs.injectionapi import SocketLabsClient
5+
from socketlabs.injectionapi.message.__imports__ import \
6+
BulkMessage, BulkRecipient, EmailAddress
7+
8+
# For more information on AMP Html, visit the following link: amp.dev/documentation
9+
10+
# build the message
11+
message = BulkMessage()
12+
13+
14+
message.subject = "Sending A Test Message (Bulk Send)"
15+
16+
message.html_body = "<html><body>" \
17+
"<h1>This HTML will show if AMP is not supported on the receiving end of the email.</h1>" \
18+
"<p>This is the Html Body of my message.</p>" \
19+
"</body></html>"
20+
message.amp_body = "<!doctype html>" \
21+
"<html amp4email>" \
22+
"<head>" \
23+
" <meta charset=\"utf-8\">" \
24+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" \
25+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" \
26+
" <style amp-custom>" \
27+
" h1 {" \
28+
" margin: 1rem;" \
29+
" }" \
30+
" </style>" \
31+
"</head>" \
32+
"<body>" \
33+
" <h1>This is the AMP Html Body of my message</h1>" \
34+
"</body>" \
35+
"</html>"
36+
37+
message.from_email_address = EmailAddress("[email protected]")
38+
message.add_to_recipient("[email protected]")
39+
message.add_to_recipient("[email protected]", "Recipient #2")
40+
message.add_to_recipient(BulkRecipient("[email protected]"))
41+
message.add_to_recipient(BulkRecipient("[email protected]", "Recipient #4"))
42+
43+
44+
# get credentials from environment variables
45+
server_id = int(os.environ.get('SOCKETLABS_SERVER_ID'))
46+
api_key = os.environ.get('SOCKETLABS_INJECTION_API_KEY')
47+
48+
# create the client
49+
client = SocketLabsClient(server_id, api_key)
50+
51+
# send the message
52+
response = client.send(message)
53+
54+
print(json.dumps(response.to_json(), indent=2))

0 commit comments

Comments
 (0)