Send Mail
Use this function to send emails from Supista ERP.
You can optionally attach generated PDF files or other supported attachments.
Usage
const emailSent = await sendMail(payload);Payload Structure
The payload object must follow this structure:
{
templateID: "id-of-the-template", // Required: Email template ID
templateData: {
row: {
columnName1: "columnValue1",
columnName2: "columnValue2",
columnName3: "columnValue3"
}
},
attachments: [], // Optional: Array of file IDs (e.g., generated PDFs)
recipients: {
to: ["xxx@xxx.ccc"] // Required: List of recipient email addresses
}
}Parameter Details
templateID (Required)
The unique ID of the email template configured in the system.
templateData (Required)
Dynamic data injected into the template.
templateData: {
row: {
// key-value pairs used inside the email template
}
}attachments (Optional)
Array of file IDs (such as PDFs generated using generatePdf) to be sent along with the email.
attachments: ["invoice_123.pdf"]recipients (Required)
Defines the email recipients.
recipients: {
to: ["recipient@example.com"]
}Example Implementation
async function customizeERP(userData, apiOperations) {
const { sendMail } = apiOperations;
const emailPayload = {
// Replace with your actual template ID
templateID: "your-email-template-id",
templateData: {
// Dynamic data passed to the email template
row: userData
},
// Add generated PDF file IDs here if needed
attachments: [],
recipients: {
// Replace with actual email address(es)
to: ["recipient@example.com"]
}
};
const emailSent = await sendMail(emailPayload);
return {
result: emailSent,
popupMsg: {
type: "message",
message: "Email sent successfully."
}
};
}