βοΈ Ibisobanuro bya Email API
Ohereza email ku biyandikishije bawe ukoresheje SMTP yawe, nta serivisi y'undi. Abiyandikisha batanga email yabo bakayemeza (double opt-in), kandi buri email ifite link yo kuva ku rutonde.
1. Shyiraho SMTP
Shyiraho izi environment variables (aho ukorera muri .env.local, no kuri Vercel: Settings β Environment Variables, hanyuma Redeploy). Iyo zitabaye zihari, PushHub ikoresha lib/server/smtp-config.js. Kuri Gmail koresha App Password, si ijambobanga risanzwe.
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USER=you@example.com
SMTP_PASS=your-app-password
SMTP_FROM=you@example.com2. Uko abantu biyandikisha bakoresheje email
Umuntu yandika email ye, agahabwa email yo kwemeza, hanyuma akaba uwemejwe amaze gukanda buto. Shyira iyi form ku rubuga rwawe (cyangwa uhamagare REST endpoint ubwayo):
<form id="email-form">
<input type="email" id="email" placeholder="you@example.com" required>
<button type="submit">Subscribe</button>
<p id="msg"></p>
</form>
<script src="https://push.newtalentsg.co.rw/sdk.js"></script>
<script>
document.getElementById('email-form').addEventListener('submit', function (e) {
e.preventDefault();
PushHub.subscribeEmail(document.getElementById('email').value, {
publicKey: 'pk_xxxxxxxxxxxxxxxx',
externalId: 'user-123', // optional
tags: ['news'], // optional
lang: 'en' // optional: rw | en | fr
})
.then(function () { document.getElementById('msg').textContent = 'Check your inbox to confirm!'; })
.catch(function (err) { document.getElementById('msg').textContent = err.message; });
});
</script>// Nta SDK: REST gusa
fetch('https://push.newtalentsg.co.rw/api/v1/email/subscribe', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ publicKey: 'pk_xxxxxxxx', email: 'someone@example.com', lang: 'rw' }),
}).then(r => r.json()).then(console.log); // { success: true, status: "pending" }Paji yo kwiyandikishaho yiteguye
Nta code ukeneye: sangiza iyi link. Yerekana form yoroshye mu rurimi rw'umusuye.
https://push.newtalentsg.co.rw/subscribe/pk_xxxxxxxxxxxxxxxx3. Ohereza email
Koresha urufunguzo rw'ibanga (sk_) kuri seriveri yawe. Koresha audience "subscribers" kugira ngo ugere ku biyandikishije bemeje (igisubizo gitanga nextOffset kugeza bose bagezweho), cyangwa "to" ku ma aderesi yihariye.
curl -X POST https://push.newtalentsg.co.rw/api/v1/email/send \
-H "Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"audience": "subscribers",
"subject": "Amakuru mashya",
"template": "newsletter",
"data": {
"title": "Amakuru y'ukwezi",
"message": "Muraho!\nDore ibyabaye uku kwezi.",
"buttonText": "Soma byose",
"buttonUrl": "https://example.com/blog",
"imageUrl": "https://example.com/cover.jpg",
"accent": "#10b981"
}
}'curl -X POST https://push.newtalentsg.co.rw/api/v1/email/send \
-H "Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"to": ["someone@example.com"],
"subject": "Welcome!",
"template": "welcome",
"data": { "title": "Welcome aboard", "message": "We are happy to have you." }
}'curl -X POST https://push.newtalentsg.co.rw/api/v1/email/send \
-H "Authorization: Bearer sk_xxxxxxxx" -H "Content-Type: application/json" \
-d '{ "to": ["someone@example.com"], "subject": "Custom", "html": "<h1>Hello</h1><p>Your own HTML.</p>" }'{
"audience": "subscribers",
"subject": "Amakuru y'ukwezi",
"template": "newsletter",
"data": {
"kicker": "Ukwakira 2026",
"title": "Amakuru y'ukwezi",
"subtitle": "Ibyaranze ikigo cyacu",
"message": "Muraho! Dore **incamake** y'ukwezi. [Soma ibisobanuro](https://example.com/docs)",
"imageUrl": "https://example.com/cover.jpg",
"imageAlt": "Ibirori by'ukwezi",
"imageCaption": "Ibirori by'ukwezi",
"cards": [
{ "kind": "article", "title": "Imbonerahamwe nshya", "text": "Twongeyeho templates.",
"imageUrl": "https://example.com/a.jpg", "buttonText": "Soma byose", "buttonUrl": "https://example.com/blog/1" },
{ "kind": "notice", "title": "Icyitonderwa", "text": "Ibiro bizafunga ku wa gatanu." }
],
"links": [
{ "url": "https://example.com/guide", "title": "Ubuyobozi", "description": "Uko ushyira PushHub ku rubuga.",
"imageUrl": "https://example.com/thumb.jpg" }
],
"buttonText": "Sura urubuga", "buttonUrl": "https://example.com",
"company": { "website": "https://example.com", "phone": "+250 788 000 000",
"social": { "facebook": "https://facebook.com/acme" } }
}
}// Node.js 18+ β kohereza ku biyandikishije bose, ukurikije nextOffset
let offset = 0;
do {
const res = await fetch('https://push.newtalentsg.co.rw/api/v1/email/send', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + process.env.PUSHHUB_SECRET_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
audience: 'subscribers',
tags: ['news'], // optional
subject: 'Hello',
template: 'announcement',
data: { title: 'Big news', message: 'Something new is live.' },
offset,
}),
});
const j = await res.json();
console.log(j);
offset = j.nextOffset; // null iyo birangiye
} while (offset != null);{
"success": true,
"total": 230, // abiyandikishije bose bahuye n'ubusabe
"recipients": 100, // abo muri iki cyifuzo
"sent": 99,
"failed": 1,
"nextOffset": 100 // null iyo nta bandi basigaye
}4. Templates
Hitamo imwe mu rwego rwa template, wuzuze data. Template zose zisangiye header (logo ibumoso, izina ry'ikigo hagati), body na footer. Cyangwa wohereze html yawe bwite.
| π | welcome | Indamutso ifite umutwe w'ibara na buto. |
| π° | newsletter | Izina ry'ikigo, ishusho (si ngombwa), umutwe n'inyandiko. |
| π’ | announcement | Umurongo w'ibara n'itangazo rinini. |
| π | promo | Igishushanyo cy'umwijima gishyizwe hagati, cy'ibigabanyirizwa. |
| βοΈ | simple | Email y'inyandiko yoroshye nta bishushanyo. |
Imirima ya data
title | Umutwe. |
subtitle | Umutwe muto munsi y'umutwe. |
kicker | Akazina gato hejuru y'umutwe (newsletter). |
message | Inyandiko y'ubutumwa. Yemera **bold**, *italic* na [label](https://link); umurongo urimo ubusa utangiza paragarafu nshya. |
buttonText | Inyandiko iri kuri buto. |
buttonUrl | Link ya buto (https://...). |
imageUrl | Aderesi y'ishusho (si ngombwa). |
imageAlt | Alt text y'ishusho nkuru. |
imageCaption | Ibisobanuro munsi y'ishusho nkuru. |
images | Andi mashusho: [{ url, alt, caption, link }] (6 ntarengwa, HTTPS). |
links | Amakarita ya link: [{ url, title, description, imageUrl }] (6 ntarengwa). Hagaragara ibyo watanze gusa; nta metadata ivanwa hanze cyangwa ihimbwa. |
cards | Ibice by'ibikubiyemo: [{ kind: article | announcement | promo | service | notice, title, text, imageUrl, buttonText, buttonUrl }] (8 ntarengwa). |
highlight | Inyandiko nini y'igabanyirizwa (promo), urugero -30%. |
code | Kode y'igabanyirizwa igaragara mu gasanduku k'utudomo. |
accent | Ibara nka #10b981. |
footer | Inyandiko yo hasi (si ngombwa). |
company | Isimbura amakuru y'ikigo kuri iyi email (website, email, phone, address, privacyUrl, preferencesUrl, logoUrl, social). |
Parameters za /api/v1/email/send
| Izina | Ibisobanuro |
|---|---|
to | Urutonde rwa aderesi za email (100 ntarengwa). |
audience | "subscribers" kugira ngo wohereze ku biyandikishije bemeje. |
externalIds | Hamwe na audience: externalId izi gusa. |
tags | Hamwe na audience: abafite imwe muri tags izi gusa. |
subject | Umutwe w'email (ngombwa). |
template | welcome | newsletter | announcement | promo | simple. |
data | Ibikubiye muri template (reba hejuru). Bisaba title cyangwa message. |
html | HTML yawe bwite (mu cyimbo cya template). |
text | Verisiyo y'inyandiko isanzwe. |
replyTo | Aderesi yo gusubizaho (Reply-To). |
lang | rw | en | fr β ururimi rw'amagambo yo kuva ku rutonde. |
offset | Aho gutangirira mu matsinda (koresha nextOffset). |
limit | Abiyandikishije kuri buri cyifuzo (100 ntarengwa). |
5. Imimerere y'uwiyandikishije no kuva ku rutonde
pending = itegereje kwemezwa, active = yakira email, unsubscribed = yavuyeho akoresheje link iri hasi ya buri email. Abakira email ni abari active gusa.
6. Header, logo na footer
Buri email ifite header (logo ibumoso, izina ry'ikigo hagati) na footer (itumanaho ryemewe, uko bavugana, imbuga nkoranyambaga, politiki y'ibanga, link yo kuva ku rutonde, copyright). Shyira logo yawe kuri public/logo.png (cyangwa ushyireho EMAIL_LOGO_URL, cyangwa aderesi ya logo muri tab y'Ikigo). Iyo nta logo ihari, haboneka akadirishya karimo inyuguti ya mbere y'izina ry'ikigo. Uzuza amakuru y'ikigo muri dashboard (Email β Ikigo).
7. Kugera muri inbox no kuva ku rutonde ukanze rimwe
Email zoherezwa ku biyandikishije zifite headers List-Unsubscribe na List-Unsubscribe-Post (RFC 8058), bityo Gmail na Apple Mail byerekana buto yabyo yo kuva ku rutonde. Footer ntivuga ko hari igenzura ryakozwe: kugira ngo email zidajya muri spam, shyiraho SPF, DKIM na DMARC kuri domain yoherezaho.
Amakosa asanzwe
401 | invalid_secret_key / invalid_public_key |
400 | subject_required / to_or_audience_required / invalid_email / invalid_template / template_data_required / content_required / too_many_recipients / invalid_link |
502 | email_failed |
500 | smtp_not_configured / server_error |
Iby'ingenzi
- Gmail yemera email zigera kuri 500 ku munsi; ku zirenze koresha SMTP ya domain yawe.
- Kugira ngo email zidajya muri spam, shyiraho SPF na DKIM kuri domain yoherezaho.
- Buri cyifuzo cyohereza email 100 ntarengwa; subiramo ukoresheje nextOffset kugeza ku bantu bose.
- Ntuzigere ushyira urufunguzo rw'ibanga (sk_) muri code ya frontend.