Basic Email
The simplest way to send an email:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Hello!',
html: '<p>Welcome to our platform.</p>'
});
Multiple Recipients
Send to multiple recipients using arrays:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: ['user1@example.com', 'user2@example.com'],
cc: ['manager@example.com'],
bcc: ['admin@example.com'],
subject: 'Team Update',
html: '<p>Important update for the team.</p>'
});
With Attachments
Include file attachments in your emails:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Invoice #1234',
html: '<p>Please find your invoice attached.</p>',
attachments: [
{
filename: 'invoice.pdf',
content: fileBuffer, // Buffer or base64 string
contentType: 'application/pdf'
}
]
});
Plain Text Alternative
Provide both HTML and plain text versions:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Welcome',
html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
text: 'Welcome! Thanks for signing up.'
});
If you only provide HTML, Transmit automatically generates a plain text version.
Add custom email headers:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Welcome',
html: '<p>Welcome!</p>',
headers: {
'X-Campaign-ID': 'campaign-123',
'X-Priority': 'high'
}
});
Reply-To Address
Set a custom reply-to address:
const response = await client.emails.send({
from: 'noreply@yourdomain.com',
replyTo: 'support@yourdomain.com',
to: 'user@example.com',
subject: 'Need Help?',
html: '<p>Reply to this email for support.</p>'
});
Tracking
Enable tracking for opens and clicks:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Product Update',
html: '<p>Check out our <a href="https://example.com/new">new features</a>!</p>',
tracking: {
opens: true,
clicks: true
}
});
Scheduled Sending
Schedule an email to be sent later:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Scheduled Newsletter',
html: '<p>This newsletter was scheduled in advance.</p>',
scheduledAt: '2025-01-15T09:00:00Z' // ISO 8601 format
});
Tag emails for better organization and filtering:
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Welcome',
html: '<p>Welcome aboard!</p>',
tags: ['onboarding', 'welcome-series', 'day-1']
});
Error Handling
Always handle errors gracefully:
try {
const response = await client.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Hello',
html: '<p>Hello World</p>'
});
console.log('Email sent:', response.id);
} catch (error) {
if (error.code === 'invalid_email') {
console.error('Invalid email address');
} else if (error.code === 'rate_limit_exceeded') {
console.error('Rate limit exceeded');
} else {
console.error('Error sending email:', error.message);
}
}
Best Practices
Verify Your Domain
Always verify your sending domain to improve deliverability
Use Templates
Create reusable templates for consistent branding
Implement Webhooks
Track delivery status with webhook events
Monitor Metrics
Check analytics to optimize your email campaigns
Next Steps