Welcome Email
Send a personalized welcome email when a new user signs up.
Send a personalized welcome email when a new user signs up.
Prerequisites
- A published transactional template with slug
welcomecontaining variablesfirstName,dashboardUrl, andtrialDaysLeft - An API key with transactional send permissions
Send the email
import { Owlat } from '@owlat/sdk-js'
const owlat = new Owlat('lm_live_...')
const result = await owlat.transactional.send({
slug: 'welcome',
email: 'mira@acme.io',
dataVariables: {
firstName: 'Mira',
dashboardUrl: 'https://app.acme.io/dashboard',
trialDaysLeft: '14',
},
})
console.log(result.data.status) // "queued"
curl -X POST https://your-deployment.convex.site/api/v1/transactional \
-H "Authorization: Bearer lm_live_..." \
-H "Content-Type: application/json" \
-d '{
"slug": "welcome",
"email": "mira@acme.io",
"dataVariables": {
"firstName": "Mira",
"dashboardUrl": "https://app.acme.io/dashboard",
"trialDaysLeft": "14"
}
}'
Error handling
Wrap the send call to handle common failure modes:
import { Owlat, ValidationError, RateLimitError } from '@owlat/sdk-js'
const owlat = new Owlat('lm_live_...')
async function sendWelcomeEmail(email: string, firstName: string) {
try {
const result = await owlat.transactional.send({
slug: 'welcome',
email,
dataVariables: {
firstName,
dashboardUrl: `https://app.acme.io/dashboard`,
trialDaysLeft: '14',
},
})
return result.data
} catch (error) {
if (error instanceof ValidationError) {
console.error('Invalid request:', error.message)
} else if (error instanceof RateLimitError) {
console.error('Rate limited — retry with backoff')
} else {
throw error
}
}
}
Full route handler
A complete Express/Hono-style handler that sends the welcome email after user creation:
import { Hono } from 'hono'
import { Owlat } from '@owlat/sdk-js'
const app = new Hono()
const owlat = new Owlat(process.env.OWLAT_API_KEY!)
app.post('/api/signup', async (c) => {
const { email, firstName } = await c.req.json()
// 1. Create user in your database
const user = await db.users.create({ email, firstName })
// 2. Send the welcome email
await owlat.transactional.send({
slug: 'welcome',
email,
dataVariables: {
firstName,
dashboardUrl: `https://app.acme.io/dashboard/${user.id}`,
trialDaysLeft: '14',
},
})
return c.json({ userId: user.id })
})
Next steps
- Billing Email — add attachments to transactional emails
- Event Automation — fire a
trial_startedevent alongside the welcome email - Transactional API reference — full request/response documentation