Sending Emails
Learn how to send transactional emails with Transactional.
Sending Emails
This guide covers everything you need to know about sending emails with Transactional.
Basic Email
Send a simple email with HTML content:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
subject: 'Hello World',
html: '<h1>Hello!</h1><p>This is a test email.</p>',
});Plain Text Alternative
Always include a plain text version for better deliverability:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
subject: 'Hello World',
html: '<h1>Hello!</h1><p>This is a test email.</p>',
text: 'Hello! This is a test email.',
});Multiple Recipients
Send to multiple recipients at once:
await client.emails.send({
from: 'hello@yourdomain.com',
to: ['user1@example.com', 'user2@example.com'],
subject: 'Team Update',
html: '<p>Here is your weekly update...</p>',
});CC and BCC
Include CC and BCC recipients:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
cc: ['manager@example.com'],
bcc: ['archive@example.com'],
subject: 'Important Update',
html: '<p>Please review the attached document.</p>',
});Attachments
Send emails with file attachments:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
subject: 'Your Invoice',
html: '<p>Please find your invoice attached.</p>',
attachments: [
{
filename: 'invoice.pdf',
content: base64EncodedContent,
contentType: 'application/pdf',
},
],
});Using Templates
Send emails using pre-built templates:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
template: 'welcome-email',
data: {
name: 'John Doe',
companyName: 'Acme Inc',
loginUrl: 'https://app.example.com/login',
},
});Custom Headers
Add custom email headers:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
subject: 'Hello',
html: '<p>Hello world!</p>',
headers: {
'X-Custom-Header': 'custom-value',
'Reply-To': 'support@yourdomain.com',
},
});Scheduling Emails
Schedule an email to be sent later:
await client.emails.send({
from: 'hello@yourdomain.com',
to: 'recipient@example.com',
subject: 'Scheduled Reminder',
html: '<p>This is your scheduled reminder.</p>',
scheduledAt: '2024-12-25T09:00:00Z',
});