Skip to main content

Overview

The Email resource enables you to send transactional emails with support for HTML, plain text, and React Email components. It includes features like CC, BCC, custom headers, and reply-to addresses.

Sending Emails

Send an email with HTML content.
const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Welcome to our service',
  html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>'
});

console.log(result.email_id);

Parameters

to
string | string[]
required
Recipient email address(es). Can be a single email or an array of up to 10 emails
from
string
required
Sender email address. Must be from a verified domain
subject
string
required
Email subject line
html
string
HTML content for the email body
text
string
Plain text content for the email body
react
React.ReactElement
React Email component for dynamic email rendering
reply_to
string
Reply-to email address
cc
string | string[]
CC recipient(s). Up to 10 addresses
bcc
string | string[]
BCC recipient(s). Up to 10 addresses
headers
Record<string, string>
Custom email headers
You must provide at least one of: html, text, or react

Returns

{
  email_id: string
}

Using React Email Components

Send emails using React components for dynamic, type-safe email templates.
import { render } from '@react-email/render';
import { WelcomeEmail } from './emails/Welcome';

const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Welcome to our service',
  react: <WelcomeEmail username="John" />
});
When using the react parameter, the SDK automatically renders the component to both HTML and plain text versions.

Advanced Examples

Email with CC and BCC

const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Order Confirmation',
  html: '<h1>Your order has been confirmed</h1>',
  cc: '[email protected]',
  bcc: ['[email protected]', '[email protected]']
});

Email with Custom Headers

const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Monthly Newsletter',
  html: '<p>Newsletter content...</p>',
  headers: {
    'X-Campaign-ID': 'newsletter-2024-03',
    'X-Priority': '3',
    'List-Unsubscribe': '<mailto:[email protected]>'
  }
});

Email with Reply-To

const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Support Ticket Created',
  html: '<p>Your support ticket has been created.</p>',
  reply_to: '[email protected]'
});

Deprecated Body Parameter

The body parameter is deprecated. Use top-level html, text, or react instead.
// ❌ Deprecated
const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Test',
  body: {
    html: '<p>Test email</p>'
  }
});

// ✅ Use this instead
const result = await contiguity.email.send({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Test',
  html: '<p>Test email</p>'
});

Error Handling

try {
  const result = await contiguity.email.send({
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Test Email',
    html: '<p>Hello!</p>'
  });
} catch (error) {
  if (error instanceof z.ZodError) {
    console.error('Validation error:', error.errors);
  } else {
    console.error('API error:', error);
  }
}

Best Practices

  • Always provide both HTML and plain text versions for better compatibility
  • Use verified sender domains to improve deliverability
  • Keep subject lines concise and meaningful
  • Limit recipient lists to 10 addresses per request
  • Use BCC for mass emails to protect recipient privacy

Build docs developers (and LLMs) love