Example #1
0
def _inbound_logic(json_body):
    message_data = json_body['Message']
    email_to = parseaddr(message_data['To'][0]['EmailAddress'])[1]
    local_portion = email_to.split('@')[0]
    from_address = parseaddr(message_data['From']['EmailAddress'])[1]
    subject = message_data.get('Subject')
    text = message_data.get('TextBody')
    html = message_data.get('HtmlBody')

    # TODO: do we need this in SocketLabs?
    # 404s make sendgrid retry the email, so respond with 200 even if
    # the address isn't found
    try:
        relay_address = RelayAddress.objects.get(address=local_portion)
    except RelayAddress.DoesNotExist as e:
        print(e)
        return HttpResponse("Address does not exist")

    # Forward to real email address
    sl_message = BasicMessage()
    sl_message.subject = subject
    sl_message.html_body = html
    sl_message.plain_text_body = text
    relay_from_address, relay_from_display = _generate_relay_From(from_address)
    sl_message.from_email_address = EmailAddress(
        relay_from_address, relay_from_display
    )
    sl_message.to_email_address.append(EmailAddress(relay_address.user.email))
    socketlabs_client = SocketLabsClient(
        settings.SOCKETLABS_SERVER_ID, settings.SOCKETLABS_API_KEY
    )
    response = socketlabs_client.send(sl_message)
    print(response)
Example #2
0
    BulkMessage, BulkRecipient, EmailAddress

# build the message
message = BulkMessage()

message.subject = "Sending A Test Message (Bulk Send)"
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_recipient("*****@*****.**")
message.add_to_recipient("*****@*****.**", "Recipient #2")
message.add_to_recipient(BulkRecipient("*****@*****.**"))
message.add_to_recipient(
    BulkRecipient("*****@*****.**", "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))
Example #3
0
def get_socketlabs_client():
    return SocketLabsClient(
        settings.SOCKETLABS_SERVER_ID, settings.SOCKETLABS_API_KEY
    )
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')

# create the client
client = SocketLabsClient(server_id, api_key)

# send the message
client.send_async(message, on_success, on_error)
from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.basicmessage import BasicMessage
from socketlabs.injectionapi.message.emailaddress import EmailAddress

serverId = #######
injectionApiKey = "????????????????"

client = SocketLabsClient(serverId, injectionApiKey);

message = BasicMessage()

message.subject = "Prove of Concept - Socketlab Email API"
message.html_body = "<html>This is a test email sent through a .py file testing the email API. Text me if you get this email. Thanks - Ron</html>"
message.plain_text_body = "This is a test email sent through a .py file testing the email API. Text me if you get this email. Thanks - Ron";

message.from_email_address = EmailAddress("no-reply@pencil_it_in.com")
message.to_email_address.append(EmailAddress("*****@*****.**", "Ron Villena"))
message.to_email_address.append(EmailAddress("*****@*****.**", "Zachary Lake"))
message.to_email_address.append(EmailAddress("*****@*****.**", "Jeannie Halvorson"))
message.to_email_address.append(EmailAddress("*****@*****.**", "Depinder Kaur"))

response = client.send(message)

# Instructions for creating email
# https://cp.socketlabs.com/servers/32586/launch/languageselection/codesample?language=json
Example #6
0
# build the message
message = BasicMessage()

message.subject = "Sending An Email Through A Proxy"
message.html_body = "<html><body>" \
                    "<h1>Sending An Email Through A Proxy</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')

# create the proxy
proxy = Proxy("127.0.0.1", 4433)

# create the client
client = SocketLabsClient(server_id, api_key, proxy)

client.number_of_retries = 2

# send the message
response = client.send(message)
client.send_async(message, on_success, on_error)

print(json.dumps(response.to_json(), indent=2))