Skip to content
OwnSMTP

Examples

Backend integration

Call OwnSMTP safely from cURL, Node.js, Python, PHP, and Go.

Set the service URL and API key in your backend environment:

Environment
EMAIL_API_URL=http://127.0.0.1:8000
EMAIL_API_KEY=your-api-key

cURL

bash
curl -X POST http://127.0.0.1:8000/v1/emails \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
  "from_email": "notifications@yourdomain.com",
  "from_name": "Your Company",
  "recipient_email": ["customer@example.com"],
  "subject": "Welcome",
  "body": "<h1>Welcome!</h1><p>Your account is ready.</p>",
  "body_type": "html",
  "reply_to": "support@yourdomain.com"
}'

Node.js with fetch

typescript
const response = await fetch(`${process.env.EMAIL_API_URL}/v1/emails`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": process.env.EMAIL_API_KEY!,
  },
  body: JSON.stringify({
    recipient_email: ["customer@example.com"],
    subject: "Welcome",
    body: "Your account is ready.",
    body_type: "plain",
  }),
});
if (!response.ok) throw new Error(`OwnSMTP returned ${response.status}`);

Python with httpx

python
import os
import httpx

response = httpx.post(
    f"{os.environ['EMAIL_API_URL']}/v1/emails",
    headers={"X-API-Key": os.environ["EMAIL_API_KEY"]},
    json={
        "recipient_email": ["customer@example.com"],
        "subject": "Welcome",
        "body": "Your account is ready.",
        "body_type": "plain",
    },
    timeout=10.0,
)
response.raise_for_status()

PHP / Laravel

php
use Illuminate\Support\Facades\Http;

$response = Http::withHeaders([
    'X-API-Key' => env('EMAIL_API_KEY'),
])->timeout(10)->post(env('EMAIL_API_URL').'/v1/emails', [
    'recipient_email' => ['customer@example.com'],
    'subject' => 'Welcome',
    'body' => 'Your account is ready.',
    'body_type' => 'plain',
]);
$response->throw();

Go

go
payload := strings.NewReader(`{
  "recipient_email":["customer@example.com"],
  "subject":"Welcome",
  "body":"Your account is ready.",
  "body_type":"plain"
}`)
req, err := http.NewRequest(http.MethodPost,
    os.Getenv("EMAIL_API_URL")+"/v1/emails", payload)
if err != nil { log.Fatal(err) }
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", os.Getenv("EMAIL_API_KEY"))
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil { log.Fatal(err) }
defer resp.Body.Close()

Production guidance

Prefer a private network path. Use HTTPS whenever traffic crosses a public or untrusted network, and configure a finite request timeout. Retry carefully: a timeout or dropped response can be ambiguous after SMTP submission, so an automatic retry may produce a duplicate message.