const { EmailApi, EmailMessage } = require('sendpost_js');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const message = new EmailMessage();
message.from = { email: 'richard@piedpiper.com' };
message.to = [{
email: 'gavin@hooli.com',
cc: [{ email: 'dinesh@bachmanity.com' }],
bcc: [{ email: 'jian@bachmanity.com' }],
}]
message.subject = 'Hello'
message.htmlBody = '<strong>it works!</strong>';
message.ippool = 'PiedPiper'
message.template = 'Welcome Mail'
const opts = {
emailMessage: message
};
try {
const data = await email.sendEmailWithTemplate(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
[
{
"to": "<string>",
"submittedAt": 123,
"messageID": "<string>",
"errorCode": 123,
"message": "<string>"
}
]
Use this API to send an email with a predefined template. This makes it easy to integrate transactional emails with minimal code.
const { EmailApi, EmailMessage } = require('sendpost_js');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const message = new EmailMessage();
message.from = { email: 'richard@piedpiper.com' };
message.to = [{
email: 'gavin@hooli.com',
cc: [{ email: 'dinesh@bachmanity.com' }],
bcc: [{ email: 'jian@bachmanity.com' }],
}]
message.subject = 'Hello'
message.htmlBody = '<strong>it works!</strong>';
message.ippool = 'PiedPiper'
message.template = 'Welcome Mail'
const opts = {
emailMessage: message
};
try {
const data = await email.sendEmailWithTemplate(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
[
{
"to": "<string>",
"submittedAt": 123,
"messageID": "<string>",
"errorCode": 123,
"message": "<string>"
}
]
This api key can be used only for sub account level operations
Email message details with template information
The body is of type object
.
A list of email message response objects.
The response is of type object[]
.