Untuk mengintegrasikan Mailtarget ke aplikasi, situs web, atau sistem Anda dengan fungsi email menggunakan NodeJS itu mudah.
Endpoints
Semua panggilan ke API perlu dimulai dengan URL dasar yang sesuai:
Mailtarget production |
Implementasi
Berikut adalah kode dasar, salin dan tempel perintah NodeJS di bawah ini ke terminal Anda, Anda dapat menyesuaikan kontennya sesuai kebutuhan Anda
Variable | Descriptions |
API_KEY | API Key in dashboard |
CURLOPT_URL |
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': 'https://transmission.mailtarget.co',
'path': '/v1/layang/transmissions',
'headers': {
'accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = JSON.stringify({
"bodyText": "Testing email with Node JS",
"bodyHtml": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>Body HTML</title></head><body><p>Body HTML</p></body></html>",
"from": {
"email": "SENDER_EMAIL",
"name": "SENDER_NAME"
},
"subject": "Example email",
"to": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"replyTo": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"cc": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"bcc": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"headers": [
{
"name": "",
"value": ""
}
],
"attachments": [
{
"mimeType": "image/png",
"filename": "FILE_NAME.png",
"value": "BASE64_ENCODED_CONTENT"
}
],
"metadata": {
"key1": "value1",
"key2": "value2",
},
"templateId":"TEMPLATE_ID"
});
req.write(postData);
req.end();
Catatan :
API_KEY → ganti dengan API Key
SENDER_EMAIL → ganti dengan sender email
SENDER_NAME → ganti dengan change with sender name
RECIPIENT_EMAIL → ganti dengan recipient email
RECIPIENT_NAME → ganti dengan recipient name
TEMPLATE_ID → ganti dengan template ID