Node.js

Integrasi AyoSend dengan Node.js / Express / NestJS. Tidak perlu library tambahan — cukup gunakan fetch (Node.js 18+).

Kirim Email

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: 'Aplikasi <no-reply@domain.com>',
    to: ['user@email.com'],
    subject: 'Kode OTP kamu',
    html: '<p>Kode OTP: <strong>847291</strong>. Berlaku 5 menit.</p>',
  }),
})
const data = await res.json()
console.log(data.id)

.env

AYOSEND_API_KEY=ays_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx