SendLayer makes it easy to send transactional and marketing emails via a simple API. This guide walks you through sending your first email using the SendLayer API, with examples for popular programming languages.
After setting up your domain and API key, you can send emails using the SDK or directly via HTTP requests.
import { SendLayer } from 'sendlayer';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 sent using SendLayer Node.js SDK',};const response = await sendlayer.Emails.send(params);
from sendlayer import SendLayersendlayer = SendLayer('your-api-key')params = { "sender": "sender@example.com", "to": "recipient@example.com", "subject": "Sending a Test Email", "text": "This is a test email sent using SendLayer's Python SDK"}response = sendlayer.Emails.send(**params)
<?phprequire_once 'vendor/autoload.php';use SendLayer\SendLayer;$sendlayer = new SendLayer('your-api-key');$params = [ 'from' => 'sender@example.com', 'to' => 'recipient@example.com', // or array of recipients 'subject' => 'Test Email', 'text' => "This is a test email sent using SendLayer's PHP SDK",];$response = $sendlayer->Emails->send($params);
require 'sendlayer'sendlayer = SendLayer::SendLayer.new('your-api-key')response = sendlayer.emails.send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Sending a Test Email', text: "This is a test email sent using SendLayer's Ruby SDK")
sl := sendlayer.New("your-api-key")resp, err := sl.Emails.Send(&sendlayer.SendEmailRequest{ From: "sender@example.com", To: "recipient@example.com", Subject: "Sending a Test Email", Text: "This is a test email sent using SendLayer's Go SDK",})
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": "Text", "PlainContent": "This is a test email sent with the SendLayer API!"}'
Replace <apiKey> with your actual SendLayer API key in the request header.
You can also send to multiple recipients, add CC/BCC, and attach files.SendLayer API also let’s you send HTML emails. This can be useful if you’d like to use a template to send welcome emails to new users.To send HTML emails, simply update the params variable to include the html object. Then enter your HTML email as a string.
const params = { from: 'sender@example.com', to: 'recipient@example.com', // or array of recipients subject: 'Test Email', html: '<html><body><p>This is a test email sent with the <a href="https://sendlayer.com">SendLayer</a> API!</p></body></html>',};
params = { "sender": "sender@example.com", "to": "recipient@example.com", "subject": "Sending a Test Email", "html": "<html><body><p>This is a test email sent with the <a href=\"https://sendlayer.com\">SendLayer</a> API!</p></body></html>"}
<?phprequire_once 'vendor/autoload.php';use SendLayer\SendLayer;$sendlayer = new SendLayer('your-api-key');$params = [ 'from' => 'sender@example.com', 'to' => 'recipient@example.com', 'subject' => 'Test Email', 'html' => '<html><body><p>This is a test email sent with the <a href="https://sendlayer.com">SendLayer</a> API!</p></body></html>',];
sendlayer = SendLayer::SendLayer.new('your-api-key')response = sendlayer.emails.send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Test Email', html: '<html><body><p>This is a test email sent with the <a href="https://sendlayer.com">SendLayer</a> API!</p></body></html>')
sl := sendlayer.New("your-api-key")resp, err := sl.Emails.Send(&sendlayer.SendEmailRequest{ From: "sender@example.com", To: "recipient@example.com", Subject: "Test Email", Html: "<html><body><p>This is a test email sent with the <a href='https://sendlayer.com'>SendLayer</a> API!</p></body></html>",})
--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>"}'
Authorizing your domain proves ownership and improves email deliverability by reducing the likelihood of your emails being marked as spam.
Where do I find my API key?
You can create or retrieve your API key from your SendLayer dashboard under the Settings » API Keys section.
Can I send emails to multiple recipients?
Yes, you can provide an array of email addresses in the to field or see our guide for more details.
How do I attach files to my email?
See our attachments guide for instructions on sending emails with attachments.
What should I do if my email is not delivered?
Check your domain authorization, verify your API key, and review the response from the API for any error messages. You can also consult the SendLayer dashboard for delivery status and logs.