import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    BasicMessage, EmailAddress


# build the message
message = BasicMessage()

message.subject = "Sending An Email With Body From Html File"

with open("../html/SimpleEmail.html", 'rb') as f:
    data = f.read()
    f.close()
message.html_body = data.decode('UTF-8')

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")


# 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)
Exemplo n.º 2
0
    :return: SendResponse
    """
    print(json.dumps(response.to_json(), indent=2))


def on_error(exception):
    """
        Handle the error response from the client
        :param exception: the Exception
        :return: Exception
        """
    print(json.dumps(exception.to_json(), indent=2))


# build the message
message = BasicMessage()

message.subject = "Sending A Test Message (Basic Send Async)"
message.html_body = "<html><body>" \
                    "<h1>Sending A Test Message</h1>" \
                    "<p>This is the Html Body of my message.</p>" \
                    "</body></html>"
message.plain_text_body = "This is the Plain Text Body of my message."

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")

# get credentials from environment variables
server_id = int(os.environ.get('SOCKETLABS_SERVER_ID'))
api_key = os.environ.get('SOCKETLABS_INJECTION_API_KEY')
Exemplo n.º 3
0
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    Attachment, BasicMessage, CustomHeader, EmailAddress

# build the message
message = BasicMessage()

message.message_id = "ComplexExample"
message.mailing_id = "BasicSend"

message.subject = "Sending A Complex Test Message"
message.html_body = "<html><body>" \
                    "<h1>Sending A Complex Test Message</h1>" \
                    "<p>This is the html Body of my message.</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."

# Setting AMP Body
message.setAmpBody = "<!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 {" \
Exemplo n.º 4
0
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    BasicMessage, EmailAddress

# build the message
message = BasicMessage()

message.subject = "Sending A ASCII Charset Email"
message.html_body = "<html><body>" \
                    "<h1>Sending A ASCII Charset Email</h1>" \
                    "<p>This is the html Body of my message.</p>" \
                    "<h2>UTF-8 Characters:</h2><p>✔ - Check</p>" \
                    "</body></html>"
message.plain_text_body = "This is the Plain Text Body of my message."

# Set the CharSet
message.charset = "ASCII"

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")

# 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)
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    Attachment, BasicMessage, EmailAddress

# build the message
message = BasicMessage()

message.subject = "Sending An Email With An Attachment"
message.html_body = "<html><body>" \
                    "<h1>Sending An Email With An Attachment</h1>" \
                    "<p>This is the Html Body of my message.</p>" \
                    "</body></html>"
message.plain_text_body = "This is the Plain Text Body of my message."

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")

# Adding Attachments
# ==========================
# Add Attachment directly to the list
attachment = Attachment(name="bus.png",
                        mime_type="image/png",
                        file_path="../img/bus.png")

message.add_attachment(attachment)

# get credentials from environment variables
server_id = int(os.environ.get('SOCKETLABS_SERVER_ID'))
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    BasicMessage, EmailAddress


# build the message
message = BasicMessage()

message.subject = "Sending An Email Using a Template"
message.api_template = 1

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")


# 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))
Exemplo n.º 7
0
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    BasicMessage, CustomHeader, EmailAddress

# build the message
message = BasicMessage()

message.subject = "Sending An Email With Custom Headers"
message.html_body = "<html><body>" \
                    "<h1>Sending An Email With Custom Headers</h1>" \
                    "<p>This is the Html Body of my message.</p>" \
                    "</body></html>"
message.plain_text_body = "This is the Plain Text Body of my message."

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")

# Add CustomHeader using a list
headers = [
    CustomHeader("example-type", "basic-send-with-custom-headers"),
    CustomHeader("message-contains", "headers")
]
message.custom_headers = headers

# Add CustomHeader directly to the list
message.custom_headers.append(CustomHeader("message-has-attachments", "true"))

# Add CustomHeader using the add_custom_header function
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    Attachment, BasicMessage, EmailAddress

# build the message
message = BasicMessage()

message.subject = "Sending A Test Message"
message.html_body = "<html><body>" \
                    "<h1>Sending A Test Message</h1>" \
                    "<p>This is the Html Body of my message.</p>" \
                    "</body></html>"
message.plain_text_body = "This is the Plain Text Body of my message."

message.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")

message.add_attachment(Attachment("invalid.png", "image/png", content=bytes()))

# 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)
Exemplo n.º 9
0
import json
import os

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.__imports__ import \
    Attachment, BasicMessage, EmailAddress

# build the message
message = BasicMessage()

message.subject = "SSending An Email With An Embedded Image"
message.html_body = "<html><body>" \
                    "<h1>Sending An Email With An Embedded Image</h1>" \
                    "<p>This is the Html Body of my message.</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.from_email_address = EmailAddress("*****@*****.**")
message.add_to_email_address("*****@*****.**")

# Adding Attachments
# ==========================
# Add Attachment directly to the list
attachment = Attachment("bus.png", "image/png", "../img/bus.png")
attachment.content_id = "bus"

message.add_attachment(attachment)

# get credentials from environment variables