Skip to main content

Getting Started with Mailblock SDK

This guide will help you get up and running with the Mailblock SDK in just a few minutes.

Prerequisites

  • Node.js 14 or higher
  • A Mailblock API key MailBlock

Installation

Install the SDK using npm:
Or using yarn:

Basic Setup

Import and initialize the SDK with your API key:

Sending Your First Email

Here’s how to send a simple email:

Using Method Chaining

The SDK also supports a fluent, chainable API:

Sending HTML Emails

You can send rich HTML emails instead of plain text:

Sending to Multiple Recipients

Send emails to multiple people with CC and BCC support:
You can also use method chaining with multiple recipients:

Scheduling Emails

Schedule emails to be sent at a future date and time:
You can also use ISO date strings:

Managing Scheduled Emails

Canceling Scheduled Emails

Cancel scheduled emails before they’re sent:

Updating Scheduled Emails

Modify scheduled emails before they’re sent:

Environment Configuration

For production applications, use environment variables for your API key:

Debug Mode

Enable debug mode during development to see detailed logs:
Debug logs include:
  • Request details and timing
  • API responses
  • Error information
  • Performance metrics

TypeScript Support

The SDK includes full TypeScript support out of the box:

Error Handling

The SDK uses a consistent response format that makes error handling straightforward:

Next Steps

Now that you’ve sent your first email, you might want to:

Need Help?