Skip to main content

Overview

SendLayer API provides a playground for developers to interact with various endpoints and send API requests. With the API, you can send emails, create and manage webhooks. Additionally, you can retrieve and monitor events related to your SendLayer account. Before you can use the SendLayer API, you’ll need to authorize your domain. Domain verification is an important steps and it helps proves domain ownership and improves email deliverability. After authorizing your domain, you’ll need to create/retrieve your API key. An API key is used to authenticate API requests.

Installation

Run the command below to install the SendLayer SDK:
npm install sendlayer
pip install sendlayer
composer require sendlayer/sendlayer-php
gem install sendlayer
go get github.com/sendlayer/sendlayer-go

Sending an Email

Once, you’ve installed the SDK, you can import it directly into your codebase and interact with the API. Here’s an example of how to send an email using the SendLayer API:
import { SendLayer } from 'sendlayer';

// Initialize the email client
const sendlayer = new SendLayer('your-api-key');

const params = {
  from: 'sender@example.com',
  to:'recipient@example.com', // or array of recipients
  subject: 'Test Email',
  text: 'This is a test email'
}

// Send a simple email
const response = await sendlayer.Emails.send(params);
from sendlayer import SendLayer

# Initialize the email client with your API key
sendlayer = SendLayer("your-api-key")

# Send an email
response = sendlayer.Emails.send(
    sender="sender@example.com",
    to="recipient@example.com",
    subject="Test Email",
    text="This is a test email"
)
<?php
require_once 'vendor/autoload.php';

use SendLayer\SendLayer;

// Initialize the email client with your API key
$sendlayer = new SendLayer('your-api-key');

// Send an email
$response = $sendlayer->Emails->send([
  'from' => 'sender@example.com',
  'to' => 'recipient@example.com',
  'subject' => 'Test Email',
  'text' => 'This is a test email'
]);
?>
require 'sendlayer'

sendlayer = SendLayer::SendLayer.new('your-api-key')

response = sendlayer.emails.send(
  from: 'sender@example.com',
  to: 'recipient@example.com',
  subject: 'Test Email',
  text: 'This is a test email'
)
package main

import (
	"fmt"
	"log"
	"github.com/sendlayer/sendlayer-go"
)

func main() {
	// Initialize the email client with your API key
	sl := sendlayer.New("your-api-key")

	// Send an email
	resp, err := sl.Emails.Send(&sendlayer.SendEmailRequest{
		From:    "sender@example.com",
		To:      "recipient@example.com",
		Subject: "Test Email",
		Text:    "This is a test email",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Email sent! Message ID:", resp.MessageID)
}
curl --request POST \
  --url https://console.sendlayer.com/api/v1/email \
  --header 'Authorization: Bearer <apiKey>' \
  --header 'Content-Type: application/json' \
  --data '{
  "From": {
    "name": "Paulie Paloma",
    "email": "paulie@example.com"
  },
  "To": [
    {
      "name": "Pattie Paloma",
      "email": "pattie@exampledomain.com"
    }
  ],
  "Subject": "This is the email subject",
  "ContentType": "HTML",
  "HTMLContent": "<html><body><p>This is a test email sent with the <a href=\"https://sendlayer.com\">SendLayer</a> API!</p></body></html>"
}'
If you’re using the cURL option, make sure to replace <apiKey> with your SendLayer API key in the request header.
SendLayer API also allows you to send emails to multiple recipients, include BCC and CC addresses, attach files to your email messages.
See our guide to learn more about sending emails using SendLayer API.

Client SDKs

SendLayer offers SDK libraries for popular programming languages that simplify the process of integrating with the API. We currently offer/support the following SDKs:

Node.js

Learn how to use the SendLayer’s Node.js SDK

Python

Learn how to use SendLayer’s Python SDK.

PHP

Learn how to use SendLayer’s PHP SDK.

Ruby

Learn how to use SendLayer’s Ruby SDK.

Go

Learn how to use SendLayer’s Go SDK.