Initialization
import { creantly } from '@creantly';
creantly.email.init({
apiKey: process.env.CREANTLY_KEY,
environment: 'production', // or 'sandbox'
});Sending Emails
// Send a transactional email
await creantly.email.send({
from: 'noreply@yourapp.com',
to: 'user@example.com',
subject: 'Welcome to Our App!',
text: 'Thanks for signing up.',
html: '<p>Thanks for signing up.</p>',
});Domains
// Create and verify a sending domain
await creantly.email.domains.create({
domain: 'yourapp.com',
});
// List verified domains
await creantly.email.domains.list();
// Delete a domain
await creantly.email.domains.delete('domain_abc123');Templates
// Create an email template
await creantly.email.templates.create({
name: 'Welcome Template',
subject: 'Welcome!',
html: '<h1>Welcome {{name}}</h1>',
});
// Retrieve a template
await creantly.email.templates.retrieve('tmpl_abc123');
// Update a template
await creantly.email.templates.update('tmpl_abc123', {
html: '<h1>Hello {{name}}!</h1>',
});
// Delete a template
await creantly.email.templates.delete('tmpl_abc123');Webhooks
// Webhook events
creantly.email.webhooks.on('email.delivered', (event) => {
console.log('Email delivered:', event.data);
});
creantly.email.webhooks.on('email.bounced', (event) => {
console.log('Email bounced:', event.data);
});Utilities
// Validate webhook signature
const isValid = creantly.email.utils.verifySignature({
payload: req.body,
signature: req.headers['creantly-email-infra-signature'],
secret: 'whsec_email_123',
});