Create a key to copy examples filled with your team.
Send emails with Node.js
Call the send API from Node.js. There is no PostShiba SDK.
Call POST /sends with fetch. PostShiba has no npm package. Use AUTH PLAIN if you send through SMTP.
send.js
1
const response = await fetch(
2
"https://postshiba.com/api/v1/teams/1/clusters/4/sends",
3
{
4
method: "POST",
5
headers: {
6
Authorization: "Bearer YOUR_API_KEY",
7
"Content-Type": "application/json",
8
},
9
body: JSON.stringify({
10
send: {
11
from: "hello@mail.example.com",
12
to: ["you@example.com"],
13
subject: "PostShiba test",
14
text: "hello from PostShiba",
15
html: "<p>hello from PostShiba</p>",
16
unique_args: { campaign_id: "cmp_123", site: "docs" },
17
},
18
}),
19
}
20
);
21
const body = await response.json();
22
console.log(body.queued, body.message_id);
smtp.js
1
import nodemailer from "nodemailer";
2
3
const transport = nodemailer.createTransport({
4
host: "smtp.postshiba.com",
5
port: 587,
6
secure: false,
7
auth: { user: "smtp_9", pass: "YOUR_PASSWORD" },
8
authMethod: "PLAIN",
9
});
10
11
await transport.sendMail({
12
from: "hello@mail.example.com",
13
to: "you@example.com",
14
subject: "PostShiba test",
15
text: "hello from PostShiba",
16
headers: {
17
"X-Capsule-Unique-Args": JSON.stringify({
18
campaign_id: "cmp_123",
19
site: "docs",
20
}),
21
},
22
});