Skip to main content

Sending Transactional Emails

This endpoint queues a single, non-promotional email for immediate sending, ideal for time-sensitive notifications triggered by user actions, such as:

  • Password resets
  • Welcome messages
  • Order confirmations

Endpoint

POST /email/send

Headers

HeaderValueRequired
AuthorizationBearer <your-api-key>✅ Yes
Content-Typeapplication/json✅ Yes

Body Parameters

ParameterTypeRequiredDescription
toString✅ YesThe recipient's email address.
fromString✅ YesThe sender's email address. Must be a verified sender.
subjectString✅ YesThe subject line of the email.
htmlString❌ OptionalThe HTML version of your email.
textString❌ OptionalThe plain text version of your email.
templateIdString❌ OptionalA custom template ID created on the platform.
templateVariablesObject❌ OptionalA list of key-value pairs to override in the template.
tip

templateId can be found in the content section of your dashboard if you saved the template from the editor.

warning

Only one of html, text, or templateId should be provided.

warning

Ensure all keys in templateVariables exist in the template.


Examples

Sending Multiple Emails (HTML, Text, and Template)


const emails = [
{
type: "html",
body: {
to: "jane.html@example.com",
from: "noreply@yourdomain.com",
subject: "Welcome to BasicsEngage!",
html: "<h1>Welcome!</h1><p>Thanks for joining our platform 🚀</p>"
}
},
{
type: "text",
body: {
to: "john.text@example.com",
from: "noreply@yourdomain.com",
subject: "Your Password Reset Request",
text: "Password Reset: Follow this link to reset your password."
}
},
{
type: "template",
body: {
to: "sara.template@example.com",
from: "noreply@yourdomain.com",
subject: "Your Order Confirmation",
templateId: "order-confirmation-123",
templateVariables: {
customer_name: "Sara Smith",
order_id: "A12345",
total: "$39.99"
}
}
}
];

async function sendEmails() {
for (const email of emails) {
try {
const response = await fetch("https://api.basicsengage.com/api/v0/dev/email/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <your-api-key>"
},
body: JSON.stringify(email.body)
});

const data = await response.json();
console.log(`✅ Sent ${email.type} email:`, data);
} catch (error) {
console.error(`❌ Failed to send ${email.type} email:`, error);
}
}
}

await sendEmails();

Responses

{
"status": "success",
"message": "Email queued successfully!",
"data": {
"messageId": "unique-queue-id",
"dailyEmailCount": 12,
"dailyEmailLimit": 100
}
}