Transactional emails are the messages your app sends in response to user actions: welcome emails, password resets, order confirmations, invoice receipts. They need to be reliable, fast, and well-formatted.
In this tutorial, you'll learn how to send transactional email from a Node.js application using Zyphr's SDK.
Prerequisites
Step 1: Install the SDK
Step 2: Initialize the client
import Zyphr from '@zyphr/sdk';
const zyphr = new Zyphr(process.env.ZYPHR_API_KEY);
Store your API key in an environment variable — never commit it to source control.
Step 3: Send a simple email
const { data } = await zyphr.emails.send({
from: 'hello@yourapp.com',
to: 'user@example.com',
subject: 'Welcome to YourApp!',
html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
});
console.log('Sent:', data.message_id);
That's it — one API call. Zyphr handles delivery via AWS SES, tracks opens and clicks, and manages bounces automatically.
Step 4: Use templates
Hardcoding HTML isn't sustainable. Create a template in the Zyphr dashboard, then reference it by ID:
const { data } = await zyphr.emails.send({
from: 'hello@yourapp.com',
to: 'user@example.com',
template: 'welcome-email',
variables: {
userName: 'Jane',
loginUrl: 'https://yourapp.com/login',
},
});
Templates use Handlebars syntax. You can use {{userName}} in your template HTML and it will be replaced with the variable value.
Step 5: Handle errors
try {
const { data } = await zyphr.emails.send({
from: 'hello@yourapp.com',
to: 'user@example.com',
subject: 'Your order has shipped',
template: 'order-shipped',
variables: { trackingUrl, orderNumber },
});
console.log('Sent:', data.message_id);
} catch (error) {
if (error.status === 422) {
console.error('Invalid email address');
} else if (error.status === 429) {
console.error('Rate limited — retry later');
} else {
console.error('Send failed:', error.message);
}
}
Step 6: Track delivery
Zyphr tracks delivery status automatically. You can check the status of any message:
const status = await zyphr.emails.get(messageId);
console.log(status.data.state); // 'delivered', 'bounced', 'opened', etc.
Or subscribe to delivery webhooks to get real-time notifications.
Next steps
Templates: Create reusable templates in the dashboard
Webhooks: Get real-time delivery notifications via webhooks
Auth integration: Use Zyphr auth to automatically send verification emails on registration
Full example
import Zyphr from '@zyphr/sdk';
const zyphr = new Zyphr(process.env.ZYPHR_API_KEY);
async function sendWelcomeEmail(user: { email: string; name: string }) {
const { data } = await zyphr.emails.send({
from: 'hello@yourapp.com',
to: user.email,
template: 'welcome-email',
variables: {
userName: user.name,
loginUrl: 'https://yourapp.com/login',
},
});
return data.message_id;
}
That's a production-ready transactional email setup in under 20 lines of code.
Get your API key →