Send templated transactional email to one recipient. Requires template defined on provider side.
npm i @superfaceai/one-sdk
const { SuperfaceClient } = require('@superfaceai/one-sdk');
// You can manage tokens here: https://superface.ai/insights
const sdk = new SuperfaceClient({ sdkAuthToken: '<< Login to get your token >>' });
async function run() {
// Load the profile
const profile = await sdk.getProfile('communication/send-templated-email@1.0.1');
// Use the profile
const result = await profile
.getUseCase('SendTemplatedEmail')
.perform({
from: 'no-reply@example.com',
to: 'jane.doe@example.com',
templateId: 'user-invitation',
templateData: {
invited_by: 'Bob',
invitation_link: 'example.com/invite?code=invite'
}
}, {
provider: 'mock'
});
// Handle the result
try {
const data = result.unwrap();
console.log(data);
} catch (error) {
console.error(error);
}
}
run();
{
"from": "no-reply@example.com",
"to": "jane.doe@example.com",
"templateId": "user-invitation",
"templateData": {
"invited_by": "Bob",
"invitation_link": "example.com/invite?code=invite"
}
}
{
"messageId": "gyax6ce9QLKQ80VOqsRX2g"
}