Instantiate kannon cli
const kannon = new KannonCli(
'<YOUR DOMAIN>',
'<API KEY>',
{
email: '[email protected]',
alias: 'Kannon',
},
{
host: '<YOU KANNON API HOST>',
},
);
async function sendHtml() {
const html = `...`;
return await kannon.sendMail(['[email protected]'], 'This is an email from kannon.js', html);
}
async function sendHtml() {
const templateId = `...`;
return await kannon.sendTemplate(['[email protected]'], 'This is an email from kannon.js', templateId);
}
const res = await cli.sendHtml(
[
// ...
],
'Send Attachment',
html,
{
attachments: [
{
filename: 'test.txt',
content: Buffer.from('Hello from Kannon!'),
},
],
},
);
You can customize the html (or the template) per recipient by using fields parameters.
const html = `Hello {{name}}!`;
return await kannon.sendMail(
[
{ email: '[email protected]', fields: { name: 'test 1' } },
{ email: '[email protected]', fields: { name: 'test 2' } }
],
'This is an email from kannon.js',
html,
);
The text between {{
and }}
will be replaced by the value of the field.
If you want to use the same field for all recipients, you can use the globalFields parameter.
const html = `Hello {{name}}! This is a global field: {{ global }}`;
return await kannon.sendMail(
[
{ email: '[email protected]', fields: { name: 'test 1' } },
{ email: '[email protected]', fields: { name: 'test 2' } }
],
'This is an email from kannon.js',
html,
{
globalFields: { global: 'global value' }
}
);