EmailResource
The email resource provides methods for sending transactional emails with support for HTML, plain text, and React components.
send()
await contiguity.email.send(params: EmailSendParams): Promise<{ email_id: string }>
Send an email message.
to
string | string[]
required
Recipient email address(es). Can be a single string or an array of up to 10 email addresses.
Sender email address. Must be from a verified domain.
HTML content of the email. Either html, text, or react must be provided.
Plain text content of the email. Either html, text, or react must be provided.
React component to render as the email body. The SDK will automatically render it to HTML and text. Either html, text, or react must be provided.
CC recipient(s). Can be a single string or an array of up to 10 email addresses.
BCC recipient(s). Can be a single string or an array of up to 10 email addresses.
Unique identifier for the sent email.
Examples
Send HTML email
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>',
text: 'Welcome! Thanks for signing up.'
});
console.log(result.email_id); // "email_..."
Send to multiple recipients
Send with React component
import { Contiguity } from 'contiguity';
import React from 'react';
const EmailTemplate = ({ name }: { name: string }) => (
<div>
<h1>Hello, {name}!</h1>
<p>Thanks for joining our service.</p>
</div>
);
await contiguity.email.send({
to: '[email protected]',
from: '[email protected]',
subject: 'Welcome!',
react: <EmailTemplate name="John" />
});
Send with custom headers and reply-to
await contiguity.email.send({
to: '[email protected]',
from: '[email protected]',
subject: 'Support Request Received',
html: '<p>We received your request and will respond shortly.</p>',
reply_to: '[email protected]',
headers: {
'X-Priority': '1',
'X-Category': 'support'
}
});
Notes
- At least one of
html, text, or react must be provided
- When using
react, the SDK automatically renders both HTML and plain text versions
- The sender domain must be verified in your Contiguity account
- Maximum 10 recipients per email (combined across
to, cc, and bcc)