| title | Send mail |
|---|---|
| description | Send transactional email with direct content or a named template. |
Sends transactional email from your project.
For the complete Mail Platform documentation (BYOK, batch sending, logs, audiences, contacts, broadcasts, webhooks, and dashboard workflows), see Mail Platform guide. This endpoint requires a **Secret Key** (`sk_live_...`). Do not call it from browser/client code.| Header | Value |
|---|---|
x-api-key |
Your sk_live_... secret key |
Content-Type |
application/json |
- Template mode:
templateIdortemplateName - Direct mode:
subject+ (htmlortext) - Do not pass both
templateIdandtemplateName. toandreplyTomust contain valid email addresses. Array forms cannot be empty (Recipient list cannot be empty,Reply-to list cannot be empty).- Subject is required after any template resolution and variable interpolation (
Subject is required). - The rendered message must include a non-empty
htmlortextbody. Requests where both come out empty after interpolation are rejected withProvide html or text(orProvide at least one of html or text content.when neither field was supplied).
When using templateName, urBackend resolves in this order:
- Project template override
- Global/system template
- Legacy embedded template fallback (older projects only)
- Escaped:
{{name}} - Raw:
{{{htmlSnippet}}}(use carefully) - Nested:
{{user.name}}
For URL values, prefer escaped placeholders like {{appUrl}}. URL-like variables are sanitized to safe http/https values.
const res = await fetch('https://api.urbackend.in/api/mail/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_YOUR_SECRET_KEY'
},
body: JSON.stringify({
to: 'user@example.com',
templateName: 'welcome',
variables: {
name: 'Ava',
projectName: 'Acme',
appUrl: 'https://acme.com'
}
})
});const res = await fetch('https://api.urbackend.in/api/mail/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_YOUR_SECRET_KEY'
},
body: JSON.stringify({
to: 'user@example.com',
replyTo: 'support@acme.com',
subject: 'Welcome to Acme',
html: '<h1>Hello</h1><p>Your account is ready.</p>'
})
});import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonBody = """
{
"to": "user@example.com",
"templateName": "welcome",
"variables": {
"name": "Ava",
"projectName": "Acme",
"appUrl": "https://acme.com"
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.urbackend.in/api/mail/send"))
.header("Content-Type", "application/json")
.header("x-api-key", "sk_live_YOUR_SECRET_KEY")
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonBody = """
{
"to": "user@example.com",
"subject": "Welcome to Acme",
"html": "<h1>Hello</h1><p>Your account is ready.</p>"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.urbackend.in/api/mail/send"))
.header("Content-Type", "application/json")
.header("x-api-key", "sk_live_YOUR_SECRET_KEY")
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}{
"success": true,
"data": {
"id": "mail_123",
"provider": "default",
"monthlyUsage": 1,
"monthlyLimit": 100
},
"message": "Mail sent successfully."
}| Status | Message | Cause |
|---|---|---|
400 Bad Request |
Invalid recipient email format / Recipient list cannot be empty |
to is missing, malformed, or an empty array |
400 Bad Request |
Invalid replyTo email format / Reply-to list cannot be empty |
replyTo is malformed or an empty array |
400 Bad Request |
Subject is required |
Subject missing, blank, or empty after template/variable interpolation |
400 Bad Request |
Provide at least one of html or text content. |
Neither html nor text supplied (or both empty after interpolation) |
400 Bad Request |
Template not found. |
templateId / templateName does not resolve |
401 Unauthorized |
Project context missing. |
Request has no resolved project |
403 Forbidden |
Forbidden. This action requires a Secret Key (sk_live_...). |
Non-secret key used |
404 Not Found |
Project not found. |
Project record missing |
429 Too Many Requests |
Monthly mail limit exceeded. |
Project quota exhausted for the month |