Skip to main content

Basic Email

The simplest way to send an email:
const response = await client.emails.send({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello!',
  html: '<p>Welcome to our platform.</p>'
});
The examples on this page use the TypeScript SDK. A Python SDK is on the way—check back soon for updates.

Multiple Recipients

Send to multiple recipients using arrays:
const response = await client.emails.send({
  from: '[email protected]',
  to: ['[email protected]', '[email protected]'],
  cc: ['[email protected]'],
  bcc: ['[email protected]'],
  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: '[email protected]',
  to: '[email protected]',
  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: '[email protected]',
  to: '[email protected]',
  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.

Custom Headers

Add custom email headers:
const response = await client.emails.send({
  from: '[email protected]',
  to: '[email protected]',
  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: '[email protected]',
  replyTo: '[email protected]',
  to: '[email protected]',
  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: '[email protected]',
  to: '[email protected]',
  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: '[email protected]',
  to: '[email protected]',
  subject: 'Scheduled Newsletter',
  html: '<p>This newsletter was scheduled in advance.</p>',
  scheduledAt: '2025-01-15T09:00:00Z' // ISO 8601 format
});

Tags for Organization

Tag emails for better organization and filtering:
const response = await client.emails.send({
  from: '[email protected]',
  to: '[email protected]',
  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: '[email protected]',
    to: '[email protected]',
    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