POST
/v1/emailsKirim Email
Kirim email transaksional ke satu atau banyak penerima. Domain pengirim harus sudah diverifikasi.
Request Body
fromstringwajibAlamat pengirim. Format: Nama <email@domain.com>. Domain harus sudah diverifikasi.
tostring | string[]wajibPenerima. Bisa satu alamat atau array (maks 50 penerima).
subjectstringwajibSubjek email. Maks 255 karakter.
htmlstringKonten HTML. Wajib ada html atau text.
textstringKonten plain text. Digunakan sebagai fallback.
templateIdstringID template. Jika diisi, html dan text diabaikan.
variablesobjectVariabel untuk mengisi template. Contoh: { "nama": "Budi", "kode": "1234" }
replyTostringAlamat email untuk balasan. Opsional.
Contoh
cURL
curl -X POST https://api.ayosend.id/v1/emails \
-H "Authorization: Bearer ays_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"from": "Toko <no-reply@toko.com>",
"to": ["pelanggan@email.com"],
"subject": "Kode OTP kamu",
"html": "<p>Kode OTP: <strong>847291</strong>. Berlaku 5 menit.</p>"
}'Node.js
const res = await fetch('https://api.ayosend.id/v1/emails', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AYOSEND_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
from: 'Toko <no-reply@toko.com>',
to: ['pelanggan@email.com'],
subject: 'Kode OTP kamu',
html: '<p>Kode OTP: <strong>847291</strong></p>',
}),
})
const data = await res.json()
console.log(data.id) // em_clxxxPHP
$response = json_decode(file_get_contents(
'https://api.ayosend.id/v1/emails', false,
stream_context_create(['http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Authorization: Bearer ' . $_ENV['AYOSEND_API_KEY'],
'Content-Type: application/json',
]),
'content' => json_encode([
'from' => 'Toko <no-reply@toko.com>',
'to' => ['pelanggan@email.com'],
'subject' => 'Kode OTP kamu',
'html' => '<p>Kode OTP: <strong>847291</strong></p>',
]),
]])
), true);
echo $response['id'];Response
200 OK
{
"id": "em_clxxxxxxxxxxxxxxxx",
"status": "queued"
}| Status | Keterangan |
|---|---|
| 200 | Email masuk antrian |
| 400 | Domain tidak diverifikasi / validasi gagal |
| 401 | API key tidak valid |
| 402 | Kredit tidak cukup — silakan top up |
| 429 | Rate limit tercapai |