The SocketLabs Email Delivery Python library allows you to easily send any type of email message supported by our Injection API, from a simple message to a single recipient, to a complex bulk message sent to multiple recipients.

Basic Message

A basic message is an email message like you’d send from a personal email client such as Outlook. A basic message can have many recipients, including multiple, To Addresses, CC Addresses, and even BCC Addresses. You can also send a file attachment in a basic message.

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.basicmessage import BasicMessage
from socketlabs.injectionapi.message.emailaddress import EmailAddress

# Your SocketLabs ServerId and Injection API key
client = SocketLabsClient(10000, "YOUR-API-KEY");

message = BasicMessage()

message.subject = "Sending A BasicMessage"
message.html_body = "<html>This is the Html Body of my message.</html>"
message.plain_text_body = "This is the Plain Text Body of my message.";

message.from_email_address = EmailAddress("[email protected]")

# A basic message supports up to 50 recipients 
# and supports several different ways to add recipients

# Add a To address by passing the email address
message.to_email_address.append(EmailAddress("[email protected]"))
message.to_email_address.append(EmailAddress("[email protected]", "Recipient #2"))

# // Adding CC Recipients
message.add_cc_email_address("[email protected]")
message.add_cc_email_address("[email protected]", "Recipient #4")

# Adding Bcc Recipients
message.add_bcc_email_address(EmailAddress("[email protected]"))
message.add_bcc_email_address(EmailAddress("[email protected]", "Recipient #6"))


response = client.send(message)

 


Bulk Message

A bulk message usually contains a single recipient per message and is generally used to send the same content to many recipients, optionally customizing the message via the use of MergeData.

from socketlabs.injectionapi import SocketLabsClient
from socketlabs.injectionapi.message.bulkmessage import BulkMessage
from socketlabs.injectionapi.message.bulkrecipient import BulkRecipient
from socketlabs.injectionapi.message.emailaddress import EmailAddress

# Your SocketLabs ServerId and Injection API key
client = SocketLabsClient(10000, "YOUR-API-KEY");

message = BulkMessage()

message.plain_text_body = "This is the body of my message sent to %%Name%%"
message.html_body = "<html>This is the HtmlBody of my message sent to %%Name%%</html>"
message.subject = tests
message.from_email_address = EmailAddress("[email protected]")

recipient1 = BulkRecipient("[email protected]")
recipient1.add_merge_data("Name", "Recipient1")
message.add_to_recipient(recipient1)

recipient2 = BulkRecipient("[email protected]", "Recipient #2")
recipient2.add_merge_data("Name", "Recipient2")
message.add_to_recipient(recipient2)

response = client.send(message)

 

How to Get Started

To run these samples you will need to obtain an API Key and ServerId number from your SocketLabs Control Panel.

I don’t have a SocketLabs Account


Create Your Account

I have a SocketLabs account


Get Your API Key & Server ID

About our Code Libraries

SocketLabs’ email API plays well with your favorite platforms and development frameworks, including .NET, PHP, Java, Node.js, Python, Go, and more! As a developer, our APIs for sending email give you all the tools you need to embed powerful email functionality into your applications.

See All Code Samples on GitHub

Looking for More Libraries & Code Samples?

Speed up development with pre-built libraries and code samples for popular languages. Choose a library below!

You’re in Good Company

We’re Always Here For You

Have questions or need help? Here’s how to reach support:

Phone

US: 800-650-1639
International: +1 484-418-1285

Tap to Call

Live Chat

Get your questions answered through live chat.

Start a Live Chat

Help Center

Have questions or need help? Visit our help center.

Get Help

SocketLabs Developers

SocketLabs is Built for Developers, By Developers

Reach the Inbox With Industry-Leading Deliverability

Integrate with Your Application in Minutes