The SocketLabs Email Delivery Node.js 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.

Send Bulk Email Without Having to Build & Maintain Your Own SMTP Email Servers

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.

const {SocketLabsClient} = require('@socketlabs/email');

const client = new SocketLabsClient(parseInt(process.env.SOCKETLABS_SERVER_ID), process.env.SOCKETLABS_INJECTION_API_KEY);

const message = {
    to: "[email protected]",
    from: "[email protected]",
    subject: "Hello from Node.js",
    textBody: "This message was sent using the SocketLabs Node.js library!",
    htmlBody: "<html>This message was sent using the SocketLabs Node.js library!</html>",
    messageType: 'basic'
}

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.

const {SocketLabsClient, BulkMessage, BulkRecipient} = require('@socketlabs/email');

const client = new SocketLabsClient(parseInt(process.env.SOCKETLABS_SERVER_ID), process.env.SOCKETLABS_INJECTION_API_KEY);

let bulkMessage = new BulkMessage();

bulkMessage.textBody = "Is your favorite color still %%FavoriteColor%%?";
bulkMessage.htmlBody = "<html>Is your favorite color still %%FavoriteColor%%?";
bulkMessage.Subject = "Sending a Bulk Message With Merge Fields";
bulkMessage.From.Email = "[email protected]";

//Use built-in classes and helper methods
let recipient1 = new BulkRecipient("[email protected]");
recipient1.addMergeData("FavoriteColor", "Green");
bulkMessage.to.push(recipient1);

//Use object literals
const recipient2 = { 
    emailAddress: "[email protected]",  
    friendlyName: "Recipient #2",
    mergeData: [
        { key: "FavoriteColor", value: "Orange" }
    ]
});

bulkMessage.to.push(recipient2);

client.send(bulkMessage);

 

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 and 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.

SocketLabs  Developers

SocketLabs is built for developers, by developers.

Reach the inbox with industry-leading deliverability.

Integrate with your application in minutes.

Looking for More Libraries & Code Samples?

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