-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbasic_send_with_amp_body.py
53 lines (42 loc) · 1.96 KB
/
basic_send_with_amp_body.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
import json
import os
from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
BasicMessage, EmailAddress
# For more information on AMP Html, visit the following link: amp.dev/documentation
# build the message
message = BasicMessage()
message.subject = "Sending A Test Message (Basic Send With AMP Body)"
message.html_body = "<html><body>" \
"<h1>This HTML will show if AMP is not supported on the receiving end of the email.</h1>" \
"<p>This is the Html Body of my message.</p>" \
"</body></html>"
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.from_email_address = EmailAddress("[email protected]")
message.add_to_email_address("[email protected]")
message.add_to_email_address("[email protected]", "Recipient #2")
message.add_to_email_address(EmailAddress("[email protected]"))
message.add_to_email_address(EmailAddress("[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))