> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thepurplebox.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Send an email

> Learn how to send your first transactional email with thePurplebox

Transactional emails are one-to-one messages automatically triggered by user actions — for example, password resets, verification codes, order confirmations, and system alerts.
With thePurplebox, sending these emails is fast, secure, and only takes a single API request.

## Prerequisites

* A thePurplebox account
* A secret API key generated from your dashboard
* A verified sending domain (recommended for best deliverability)

## Sending an email

Sending a transactional email requires one API call with three basic parameters:

* `to`: A single email address or an array of recipients
* `subject`: The email subject line
* `body`: The message content (plain text or HTML)

<Tabs>
  <Tab label="JavaScript" title="JavaScript" icon="js">
    ```javascript theme={null}
    await fetch('https://api.thepurplebox.io/v1/send', {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer <API_KEY>"
      },
      body: JSON.stringify({
        to: "hello@yourdomain.com",
        subject: "Welcome to thePurplebox!",
        body: "<h1>Your account is ready!</h1>"
      })
    })
    ```
  </Tab>

  <Tab label="Go" title="Go" icon="golang">
    ```go theme={null}
    package main

    import (
    	"bytes"
    	"encoding/json"
    	"net/http"
    )

    func main() {
    	payload := map[string]interface{}{
    		"to":      "hello@yourdomain.com",
    		"subject": "Welcome to thePurplebox!",
    		"body":    "<h1>Your account is ready!</h1>",
    	}

    	jsonData, _ := json.Marshal(payload)
    	req, _ := http.NewRequest("POST", "https://api.thepurplebox.io/v1/send", bytes.NewBuffer(jsonData))
    	req.Header.Set("Authorization", "Bearer <API_KEY>")
    	req.Header.Set("Content-Type", "application/json")

    	client := &http.Client{}
    	client.Do(req)
    }
    ```
  </Tab>

  <Tab label="Python" title="Python" icon="python">
    ```python theme={null}
    import requests

    url = "https://api.thepurplebox.io/v1/send"

    payload = {
        "to": "hello@yourdomain.com",
        "subject": "Welcome to thePurplebox!",
        "body": "<h1>Your account is ready!</h1>"
    }

    headers = {
        "Authorization": "Bearer <API_KEY>",
        "Content-Type": "application/json"
    }

    requests.post(url, json=payload, headers=headers)
    ```
  </Tab>

  <Tab label="PHP" title="PHP" icon="php">
    ```php theme={null}
    <?php

    $url = "https://api.thepurplebox.io/v1/send";

    $payload = [
        "to" => "hello@yourdomain.com",
        "subject" => "Welcome to thePurplebox!",
        "body" => "<h1>Your account is ready!</h1>"
    ];

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Authorization: Bearer <API_KEY>",
        "Content-Type: application/json"
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);
    ?>
    ```
  </Tab>

  <Tab label="Java" title="Java" icon="java">
    ```java theme={null}
    import java.net.http.HttpClient;
    import java.net.http.HttpRequest;
    import java.net.http.HttpResponse;
    import java.net.URI;

    public class SendEmail {
        public static void main(String[] args) throws Exception {
            String json = """
            {
                "to": "hello@yourdomain.com",
                "subject": "Welcome to thePurplebox!",
                "body": "<h1>Your account is ready!</h1>"
            }
            """;

            HttpClient client = HttpClient.newHttpClient();
            HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.thepurplebox.io/v1/send"))
                .header("Content-Type", "application/json")
                .header("Authorization", "Bearer <API_KEY>")
                .POST(HttpRequest.BodyPublishers.ofString(json))
                .build();

            HttpResponse<String> response = client.send(request, 
                HttpResponse.BodyHandlers.ofString());
        }
    }
    ```
  </Tab>

  <Tab label="Rust" title="Rust" icon="rust">
    ```rust theme={null}
    use reqwest;
    use serde_json::json;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let client = reqwest::Client::new();
        
        let payload = json!({
            "to": "hello@yourdomain.com",
            "subject": "Welcome to thePurplebox!",
            "body": "<h1>Your account is ready!</h1>"
        });

        let response = client
            .post("https://api.thepurplebox.io/v1/send")
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer <API_KEY>")
            .json(&payload)
            .send()
            .await?;

        Ok(())
    }
    ```
  </Tab>

  <Tab label="Ruby" title="Ruby">
    ```ruby theme={null}
    require 'net/http'
    require 'json'
    require 'uri'

    uri = URI('https://api.thepurplebox.io/v1/send')
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(uri)
    request['Content-Type'] = 'application/json'
    request['Authorization'] = 'Bearer <API_KEY>'

    request.body = {
      to: 'hello@yourdomain.com',
      subject: 'Welcome to thePurplebox!',
      body: '<h1>Your account is ready!</h1>'
    }.to_json

    response = http.request(request)
    ```
  </Tab>

  <Tab label="C#" title="C#">
    ```csharp theme={null}
    using System;
    using System.Net.Http;
    using System.Text;
    using System.Text.Json;
    using System.Threading.Tasks;

    public class SendEmail
    {
        public static async Task Main()
        {
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer <API_KEY>");

            var payload = new
            {
                to = "hello@yourdomain.com",
                subject = "Welcome to thePurplebox!",
                body = "<h1>Your account is ready!</h1>"
            };

            var json = JsonSerializer.Serialize(payload);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            var response = await client.PostAsync(
                "https://api.thepurplebox.io/v1/send", 
                content
            );
        }
    }
    ```
  </Tab>

  <Tab label="ASP.NET" title="ASP.NET">
    ```csharp theme={null}
    using Microsoft.AspNetCore.Mvc;
    using System.Net.Http;
    using System.Text;
    using System.Text.Json;

    [ApiController]
    [Route("api/[controller]")]
    public class EmailController : ControllerBase
    {
        private readonly IHttpClientFactory _httpClientFactory;

        public EmailController(IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
        }

        [HttpPost("send")]
        public async Task<IActionResult> SendEmail()
        {
            var client = _httpClientFactory.CreateClient();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer <API_KEY>");

            var payload = new
            {
                to = "hello@yourdomain.com",
                subject = "Welcome to thePurplebox!",
                body = "<h1>Your account is ready!</h1>"
            };

            var json = JsonSerializer.Serialize(payload);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            var response = await client.PostAsync(
                "https://api.thepurplebox.io/v1/send", 
                content
            );

            if (response.IsSuccessStatusCode)
            {
                return Ok(new { message = "Email sent successfully" });
            }

            return BadRequest(new { message = "Failed to send email" });
        }
    }
    ```
  </Tab>

  <Tab label="cURL" title="cURL" icon="terminal">
    ```bash theme={null}
    curl -X POST https://api.thepurplebox.io/v1/send \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer <API_KEY>" \
      -d '{
        "to": "hello@yourdomain.com",
        "subject": "Welcome to thePurplebox!",
        "body": "<h1>Your account is ready!</h1>"
      }'
    ```
  </Tab>
</Tabs>
