Send Email
Send transactional emails using the YourSend API — reliable delivery from your own verified domain.
Basic Email
send-email.ts
import { YourSend } from 'yoursend';
const ys = new YourSend({ apiKey: 'ys_live_...' });
await ys.send({
channel: 'email',
to: 'user@example.com',
subject: 'Order Confirmation',
html: '<h1>Your order is confirmed!</h1>',
});HTML Email
Send rich HTML emails with inline styles. YourSend automatically generates a plain text version.
html-email.ts
await ys.send({
channel: 'email',
to: 'user@example.com',
subject: 'Welcome aboard!',
html: `
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto;">
<h1 style="color: #2563EB;">Welcome to {{app_name}}</h1>
<p>Hi {{name}},</p>
<p>Thanks for signing up. Here's what you can do next:</p>
<a href="{{dashboard_url}}" style="
display: inline-block;
background: #2563EB;
color: white;
padding: 12px 24px;
border-radius: 6px;
text-decoration: none;
">Go to Dashboard</a>
</div>
`,
data: {
name: 'Alex',
app_name: 'YourSend',
dashboard_url: 'https://www.yoursend.dev/dashboard',
},
});Merge Tags
Use {{tag_name}} syntax in your subject and body. Pass values via the data object.
merge-tags.ts
await ys.send({
channel: 'email',
to: 'user@example.com',
subject: '{{name}}, your invoice is ready',
html: '<p>Hi {{name}}, your invoice for {{amount}} is attached.</p>',
data: {
name: 'Alex',
amount: '$49.00',
},
});Sender Address
The From address is set automatically from your verified sending identity — there is no per-request from field. Verify a domain (or a single sender address) under Dashboard → Domains, and emails are sent from that identity — for example noreply@yourdomain.com. You can also set a reply-to address there. Until a domain is verified, sends are rejected with an invalid_sender error.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| channel | string | Yes | "email" |
| to | string | Yes | Recipient email address |
| subject | string | Yes* | Email subject line (or comes from the template) |
| html | string | Yes* | HTML body content |
| text | string | No | Plain text fallback |
| template_id | string | Yes* | Template ID (alternative to html/subject) |
| data | object | No | Merge-tag values for {{...}} placeholders |
* Either html or template_id is required.