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

ParameterTypeRequiredDescription
channelstringYes"email"
tostringYesRecipient email address
subjectstringYes*Email subject line (or comes from the template)
htmlstringYes*HTML body content
textstringNoPlain text fallback
template_idstringYes*Template ID (alternative to html/subject)
dataobjectNoMerge-tag values for {{...}} placeholders
ccarrayNoCopied recipients (max 24). Each one is billed as a message.
bccarrayNoBlind-copied recipients (max 24). Each one is billed as a message.

* Either html or template_id is required.

Cc and Bcc

Copy other people on a send by passing arrays of addresses. Up to 24 per list. Recipients on bcc are hidden from everyone else on the message.

Node.js
await ys.send({
  channel: 'email',
  to: 'customer@example.com',
  cc: ['manager@example.com'],
  bcc: ['archive@example.com'],
  subject: 'Your invoice',
  html: '<p>Invoice attached.</p>',
});

Each recipient is billed as a message. The send above delivers to three people and costs three messages. Your balance is checked against the full count before anything is sent.