Services
Mail – E‑Mail senden
Versendet eine E‑Mail basierend auf Template oder freiem HTML, wahlweise mit Brand‑Wrap und SMTP‑Account.
Route
- Methode: POST
- URL: /api/mail/send
- Auth:
x-api-key
(Header)
Request
- templateId: string (optional; exklusiv zu subject+html)
- to: string|string[]
- variables: object|string (optional)
- subject: string (optional; wenn kein templateId)
- html: string (optional; wenn kein templateId)
- smtpAccountId: string (erforderlich, wenn nicht via Template)
- brandId: string (optional)
- replyTo: string (optional; überschreibt Brand.replyTo)
- attachments: Array<{ filename, content|path, contentType?, cid?, encoding? }>
/api/mail/send (POST)
{
"brandId": "BRAND_ID",
"smtpAccountId": "SMTP_ID",
"templateId": "TEMPLATE_ID",
"to": [
"you@example.com"
],
"variables": {
"name": "You"
},
"attachments": [
{
"filename": "info.txt",
"content": "aGk=",
"encoding": "base64"
}
]
}
curl -X POST "https://dev.nuvisphere.de/api/mail/send" \
-H "Content-Type: application/json" \
-H "x-api-key: API_KEY"
-d '{
"brandId": "BRAND_ID",
"smtpAccountId": "SMTP_ID",
"templateId": "TEMPLATE_ID",
"to": [
"you@example.com"
],
"variables": {
"name": "You"
},
"attachments": [
{
"filename": "info.txt",
"content": "aGk=",
"encoding": "base64"
}
]
}'
// server-side (Node/Next.js)
const res = await fetch("https://dev.nuvisphere.de/api/mail/send", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": process.env.MAILER_API_KEY!,
},
body: JSON.stringify({
"brandId": "BRAND_ID",
"smtpAccountId": "SMTP_ID",
"templateId": "TEMPLATE_ID",
"to": [
"you@example.com"
],
"variables": {
"name": "You"
},
"attachments": [
{
"filename": "info.txt",
"content": "aGk=",
"encoding": "base64"
}
]
}),
});
if (!res.ok) throw new Error(`Request failed ${res.status}`);
const json = await res.json();
- API Key niemals im Browser verwenden – nur serverseitig (z. B.
process.env.MAILER_API_KEY
). - Lässt du optionale Felder weg, nutzt die API ggf. Template-/Defaultwerte.
Response
{
"ok": true,
"id": "MESSAGE_ID",
"accepted": [
"you@example.com"
]
}