Send Email

Send transactional emails using the YourSend API. Powered by AWS SES for reliable delivery.

Basic Email

send-email.ts
import { YourSend } from 'yoursend';

const ys = new YourSend('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>
  `,
  tags: {
    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 tags 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>',
  tags: {
    name: 'Alex',
    amount: '$49.00',
  },
});

Attachments

attachment.ts
await ys.send({
  channel: 'email',
  to: 'user@example.com',
  subject: 'Your report',
  html: '<p>Please find your report attached.</p>',
  attachments: [
    {
      filename: 'report.pdf',
      content: base64EncodedContent,
      content_type: 'application/pdf',
    },
  ],
});

Custom From Address

Use a verified domain to customize the sender address:

await ys.send({
  channel: 'email',
  from: 'Team YourApp <hello@yourapp.com>',
  to: 'user@example.com',
  subject: 'Welcome!',
  html: '<p>Hello from YourApp!</p>',
});

Parameters

ParameterTypeRequiredDescription
channelstringYes"email"
tostringYesRecipient email address
fromstringNoSender address (must be verified domain)
subjectstringYesEmail subject line
htmlstringYes*HTML body content
textstringNoPlain text fallback
template_idstringYes*Template ID (alternative to html)
tagsobjectNoMerge tag values
attachmentsarrayNoFile attachments
reply_tostringNoReply-to address

* Either html or template_id is required.