Documentation

Sending Email

API
Integration Guide

Send emails programmatically via our HTTP API or integrate with your existing email infrastructure using SMTP. Built for developers, designed for scale.

Prerequisites Required

Before you can send emails through Laneful, you must complete these essential setup steps:

New to Laneful? Start with our Getting Started guide.

REST API

Simple HTTP integration

SMTP Support

Standard email protocols

API
Integration

Overview

Laneful provides two methods for sending emails: HTTP API for programmatic access and SMTP for traditional email client integration. Check out our official SDKs for easier integration in 8 programming languages.

Sample Organization Endpoints

Below are sample endpoints. After you register and create an organization, you'll get your unique endpoints:

https://your-endpoint.z1.send.laneful.net
your-endpoint.z1.send.laneful.net

One host serves everything: the HTTP API (including the Custom Webhooks ingest endpoint) and SMTP. The HTTP API is HTTPS-only, so every request it processes is encrypted; plain HTTP requests are never processed.

Note: These are sample endpoints. Your organization's endpoints (for example abcd1234efgh5678.z1.send.laneful.net) are shown in the dashboard under Workspaces → Workspace Settings → API Keys. To see them, register or log in to your account.

Quick Start

Send Your First Email

Use this example to send your first email via the HTTP API:

Sample code: Replace your-endpoint.z1.send.laneful.net with your organization's endpoint from the dashboard.

curl --request POST \
  --url https://your-endpoint.z1.send.laneful.net/v1/email/send \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'content-type: application/json' \
  --data '{
    "emails": [{
      "from": {
        "email": "noreply@yourdomain.com",
        "name": "Your App Name"
      },
      "to": [{
        "email": "user@example.com",
        "name": "User Name"
      }],
      "subject": "Welcome to Our Service",
      "text_content": "Hello,\n\nWelcome to our service! We're excited to have you on board.\n\nIf you have any questions, feel free to reach out to our support team.\n\nBest regards,\nThe Team"
    }]
  }'

Authentication

API Key Authentication

All API requests require authentication using a Bearer token in the Authorization header.

Authorization: Bearer YOUR_API_KEY

Note: Replace YOUR_API_KEY with an API key created under Workspaces → Workspace Settings → API Keys → Create Private Key. The key sends through the track you assign to it, unless the sending domain has its own track.

Important: The "from" email address must be from a domain verified in the same workspace as the API key. Otherwise the request fails with 401 Authentication failed.

HTTP API

Send Email Endpoint

Endpoint

POST /v1/email/send

Request Body

{
  "emails": [{
    "from": {
      "email": "sender@yourdomain.com",
      "name": "Sender Name"
    },
    "to": [{
      "email": "recipient@example.com", 
      "name": "Recipient Name"
    }],
    "subject": "Email Subject",
    "text_content": "Plain text content",
    "html_content": "<p>HTML content</p>",
    "reply_to": {
      "email": "reply@yourdomain.com",
      "name": "Reply Name"
    },
    "cc": [{"email": "cc@example.com", "name": "CC Name"}],
    "bcc": [{"email": "bcc@example.com", "name": "BCC Name"}],
    "attachments": [{
      "file_name": "document.pdf",
      "content": "base64-encoded-content",
      "content_type": "application/pdf"
    }],
    "headers": {
      "X-Custom-Header": "value"
    },
    "send_time": 0,
    "webhook_data": {
      "campaign_id": "camp_123"
    },
    "tag": "newsletter"
  }]
}

emails can hold several emails. Send Content-Type: application/json exactly: a charset parameter (application/json; charset=utf-8) is rejected with 400.

Required Fields

  • • from - Valid sender email address
  • • subject - Required for every email, including template sends (templates don't provide a subject)
  • • At least one recipient in to, cc, or bcc
  • • Either text_content, html_content, or template_id

Response (200 OK)

{
  "status": "accepted"
}

With mail_settings.return_message_ids (see Mail Settings):

{
  "status": "accepted",
  "message_ids": [
    "H-0-019844e340027d728a7cfda632e14d0a-1234"
  ]
}

Error Responses

Errors return a JSON body with an error message, for example:

{
  "error": "Missing email subject"
}
  • • 400 - Invalid request (for example Missing email subject, Invalid recipient email: …, Send time is in the past, Too many recipients: …). Nothing was sent; fix the request before retrying.
  • • 401 - Missing Authorization header, Missing or invalid API key or Authentication failed (unknown key, the sender domain isn't verified in the key's workspace, or the request IP isn't allowed for the key). Nothing was sent.
  • • 408 - Request timed out after 60 seconds. The emails may already have been accepted.
  • • 413 - Request payload too large (the request body is limited to 50 MB). Nothing was sent.
  • • 500 - Internal server error. Some emails in the request may already have been accepted.

After a 408 or a dropped connection, retry with the same idempotency key so each email goes out only once. After a 500, some emails may already be on their way, so check your events before resending.

Mail Settings

The optional mail_settings object applies to the whole request:

{
  "emails": [{ ... }],
  "mail_settings": {
    "return_message_ids": true,
    "idempotency_key": "order-1042-receipt"
  }
}
return_message_idsboolean

Return message_ids in the response: one ID per email, in the order of emails. Every email must then have exactly one recipient across to, cc and bcc; otherwise the request is rejected with 400. Each ID is the message_id on that email's webhook events, and the delivered email's Message-ID header is <message_id@laneful-host>. Default: false.

idempotency_keystringexperimental

Makes retries safe: a retried request with the same key doesn't send its emails again. 1 to 36 bytes long in UTF-8 (36 ASCII characters). If your organization already sent a request with the same key in the last hour, Laneful answers 200 {"status": "accepted"} (without message_ids) and sends nothing. The request body isn't compared, so use a new key for every distinct request and reuse it only for retries of that request. If a request fails with 500, its key isn't kept and a retry is processed as a new request. Duplicate detection is best effort. The key is read only from mail_settings; an Idempotency-Key HTTP header is ignored.

sandbox_modeboolean

Test your connection safely: the request is accepted, and nothing is stored or sent. Sandbox mode skips email and API key validation, so use it to check that your client can reach the API rather than to validate requests. Default: false.

Field Descriptions

For the full schema documentation, check the OpenAPI specification.

from

Sender email address and optional display name (required). Its domain must be verified in the API key's workspace.

from_header

Optional address and display name for the visible From header, if it should differ from from. Its domain must be the domain of from or that domain's parent.

to

Primary recipients array. Maximum 1000 recipients across to, cc and bcc of all emails in the request

cc

Carbon copy recipients array (optional)

bcc

Blind carbon copy recipients array (optional)

subject

Email subject line (required, also when template_id is set)

text_content

Plain text email content. With template_id, it replaces the template's text part

html_content

HTML email content for rich formatting. With template_id, it replaces the template's HTML part

template_id

ID of a template to use as the email content. Laneful looks up the template when it processes the email; if no such template exists, the email isn't sent and a drop event is reported

template_data

Data object to populate template variables using Handlebars syntax. It applies to template content only, not to text_content or html_content. Without template_data, the template is sent as is, with its {{...}} placeholders unreplaced

attachments

Base64 encoded file content with a content_type (required) and either a file_name or, for inline images, an inline_id

headers

Custom email headers as key-value pairs. From, To, Cc, Bcc, Reply-To, Subject and Message-ID are ignored: set them with the request fields (Laneful generates the Message-ID). Names and values can't contain line breaks, and a name can appear only once. A List-Unsubscribe header replaces Laneful's unsubscribe headers

reply_to

Reply-to email address and optional display name

send_time

Unix timestamp in seconds for scheduled sending, at most 72 hours in the future. A time in the past is rejected with 400. Use 0 (or omit it) for immediate sending

webhook_data

Custom string key-value pairs (max 20 keys; keys up to 50 bytes, values up to 100 bytes). Every webhook event for this email carries this object, unchanged, as its metadata field

tag

Label for organizing and tracking emails (max 100 bytes)

tracking

Email tracking settings for opens, clicks, and unsubscribes

Tracking Settings Schema

The tracking object controls email analytics and unsubscribe behavior.

opensboolean

Track when recipients open emails by adding a tracking pixel to the HTML content (default: true)

clicksboolean

Track when recipients click links in emails (default: true)

unsubscribesboolean

Add List-Unsubscribe and one-click List-Unsubscribe-Post headers and replace %%UNSUBSCRIBE_URL%% in the content with the recipient's unsubscribe link (default: true). When false, the token is left in the content as is. See Email Unsubscribes

unsubscribe_group_idinteger | null

Optional unsubscribe group ID. If not specified, uses global unsubscribe list. Laneful automatically skips addresses that unsubscribed from this group or globally, even when unsubscribes is false.

unsubscribe_group_namestring | null

Selects the unsubscribe group by its exact name instead of its ID. Ignored when unsubscribe_group_id is set. A name that matches no group falls back to the global list without an error; no group is created.

tracking_pixel_tagstring | null

Text in the HTML content to replace with the open-tracking pixel. If not set (or not found), the pixel is added at the end of the HTML body.

Example

{
  "tracking": {
    "opens": true,
    "clicks": true,
    "unsubscribes": true,
    "unsubscribe_group_id": 123
  }
}

Email Templates

Using Templates with Handlebars

Templates support full Handlebars syntax for dynamic content including loops and conditions. Use template_id to reference a template created under Design & Content → Templates and template_data to provide substitution values. The request still needs a subject.

Template Example

{
  "emails": [{
    "from": {
      "email": "noreply@yourdomain.com",
      "name": "Your App"
    },
    "to": [{
      "email": "user@example.com",
      "name": "John Smith"
    }],
    "subject": "Welcome to Our Service",
    "template_id": "1234",
    "template_data": {
      "user_name": "John Smith",
      "company_name": "Acme Corp",
      "activation_link": "https://app.example.com/activate/abc123",
      "support_email": "support@yourdomain.com"
    }
  }]
}

Template Content (HTML)

<html>
<body>
  <h1>Welcome to {{company_name}}, {{user_name}}!</h1>
  
  <p>We're excited to have you on board. To get started, please activate your account:</p>
  
  <a href="{{activation_link}}" style="background: #007bff; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;">
    Activate Account
  </a>
  
  <p>If you have any questions, contact us at {{support_email}}</p>
  
  {{#if premium_user}}
  <div style="background: #f8f9fa; padding: 15px; border-radius: 5px;">
    <h3>Premium Features Available</h3>
    <p>As a premium user, you have access to advanced features!</p>
  </div>
  {{/if}}
  
  <footer>
    <p>Thanks,<br>The {{company_name}} Team</p>
  </footer>
</body>
</html>

Handlebars Features

{{variable}}

Simple variable substitution

{{#if condition}}...{{/if}}

Conditional blocks

{{#each items}}...{{/each}}

Iteration over arrays

{{#unless condition}}...{{/unless}}

Inverse conditional blocks

Template Data Format

The template_data field accepts a map of string keys to any values for substitutions:

"template_data": {
  "user_name": "John Smith",
  "company_name": "Acme Corp",
  "premium_user": true,
  "total_amount": 99.99,
  "items": ["item1", "item2"],
  "user_data": {"age": 25}
}

Note: Template_data accepts any JSON-serializable values including strings, numbers, booleans, arrays, and objects.

SMTP Configuration

SMTP Settings

Sample configuration: Your actual SMTP settings will be available after registration.

Server Settings

Host:your-endpoint.z1.send.laneful.net
Port:25, 587 or 2525 (STARTTLS), or 465 (TLS on connect)
Security:STARTTLS or SSL/TLS

Authentication

Username:apikey
Password:Your API Key

Note: Port 25 is often blocked by hosting providers. Use port 587 instead. Configure your client to require TLS (STARTTLS, or port 465), because your API key is the SMTP password. The key and the sender domain are checked at MAIL FROM: an invalid key or an unverified domain gets 535 Authentication failed there, even though AUTH succeeded. Messages are limited to 50 MB and 1000 recipients.

X-Laneful-API Header (Optional)

When sending via SMTP, you can add an optional X-Laneful-API header in JSON format to configure webhook data, tags, and tracking settings for individual messages. A message whose header isn't valid is not sent and produces a drop event with reason invalid X-Laneful-API header.

Header Format

X-Laneful-API: {"webhook_data": {"campaign_id": "camp_123"}, "tag": "newsletter", "tracking": {"opens": true, "clicks": true, "unsubscribes": true, "unsubscribe_group_id": 123}}

Available Options

webhook_data

Custom data sent to webhook endpoints (max 20 keys; keys up to 50 bytes, values up to 100 bytes)

tag

Label for organizing and tracking emails (max 100 bytes)

tracking

Override default tracking settings for this message (opens, clicks, unsubscribes)

Best Practices

✓ Do

  • • Use verified sender domains
  • • Include both text and HTML content
  • • Implement proper error handling
  • • Use meaningful subject lines
  • • Include unsubscribe links where required
  • • Test emails before production

✗ Don't

  • • Send from unverified domains
  • • Use misleading subject lines
  • • Send emails without proper authentication
  • • Ignore bounce and complaint handling
  • • Send bulk emails without proper consent
  • • Hardcode API keys in client-side code

Troubleshooting

Common Issues

401 Unauthorized

Check your API key and ensure it's correctly formatted in the Authorization header.

  • • Verify API key is active and not expired
  • • Ensure proper Bearer token format
  • • Check for any extra spaces or characters
  • • Make sure the sender domain is verified in the same workspace as the key
  • • If the key has allowed IPs, make sure your server's IP is one of them

400 Missing Content-Type

Send the header Content-Type: application/json with no charset or other parameters.

Email not delivered

Verify sender domain and check recipient email validity.

  • • Ensure sender domain is verified
  • • Check recipient email format
  • • Review spam folder and filters

SMTP connection failed

Verify SMTP settings and network connectivity.

  • • Check host and port settings
  • • Verify TLS/SSL configuration
  • • Ensure firewall allows SMTP traffic