# Send email from Node.js

> Send transactional email from plain Node.js with Scribase Mail, either the resend SDK or a raw fetch call to a Resend-shaped REST API.

Source: https://scribase.com/mail/send-email-node

Two ways to send from Node, no framework required: the official resend SDK pointed at https://mail-api.scribase.com, or a plain HTTP POST with no dependency at all.

## With the resend SDK

Existing Resend code keeps its shape; only the client construction changes.

```ts
import { Resend } from 'resend';

// Before: const resend = new Resend(process.env.RESEND_API_KEY);
const resend = new Resend(process.env.SCRIBASE_MAIL_KEY, {
  baseUrl: 'https://mail-api.scribase.com',
});

await resend.emails.send({
  from: 'Acme <hello@acme.com>',
  to: ['you@example.com'],
  subject: 'It works',
  html: '<p>Sent through Scribase Mail.</p>',
});
```

## With no dependency

Node's built-in fetch works directly against the REST API — useful in a script, a worker or anywhere adding a package is overkill.

_send.mjs_

```js
// send.mjs — no framework, just Node's fetch
const response = await fetch('https://mail-api.scribase.com/emails', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SCRIBASE_MAIL_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    from: 'Acme <hello@mail.acme.com>',
    to: ['you@example.com'],
    subject: 'It works',
    html: '<p>Sent through Scribase Mail.</p>',
  }),
});

if (!response.ok) {
  throw new Error(`Scribase Mail send failed: ${response.status}`);
}
const { id } = await response.json();
console.log(id);
```

## Switching existing Resend code with one environment variable

If your code already reads RESEND_BASE_URL (the resend SDK does), no code change is needed at all.

```env
# No code change: the resend SDK reads this variable
RESEND_BASE_URL=https://mail-api.scribase.com
```

## Get delivery events back

Webhooks are signed in the Standard Webhooks format and also carry svix-* headers, so resend.webhooks.verify() accepts them unchanged.

_An Express or Next.js handler_

```ts
import { Resend } from 'resend';

const resend = new Resend(process.env.SCRIBASE_MAIL_KEY, { baseUrl: 'https://mail-api.scribase.com' });

export async function POST(req: Request) {
  const payload = await req.text();
  // Scribase Mail signs in the Standard Webhooks format and also sends the
  // same values as svix-* headers, so the resend verifier works unchanged.
  const event = resend.webhooks.verify({
    payload,
    headers: {
      id: req.headers.get('svix-id')!,
      timestamp: req.headers.get('svix-timestamp')!,
      signature: req.headers.get('svix-signature')!,
    },
    webhookSecret: process.env.SCRIBASE_MAIL_WEBHOOK_SECRET!, // whsec_...
  });
  // event.type: 'email.delivered', 'email.bounced', 'email.opened', ...
  return new Response('ok');
}
```

## FAQ

**Do I have to use the resend package?**

No. Scribase Mail is a REST API; any HTTP client, including Node's built-in fetch, sends mail without a dependency.

**What does a send return?**

A JSON body with the new email id, the same shape as Resend's response, for example { "id": "..." }.

**How do I check whether an email actually delivered?**

GET /emails/:id/events, or a webhook: delivered, bounced, complained and opened/clicked events are logged and can be signed and pushed to your own endpoint.

## Related

- [Scribase Mail overview](https://scribase.com/mail)
- [Scribase Mail docs](https://scribase.com/mail/docs)
- [Migrate from Resend](https://scribase.com/mail/migrate-from-resend)
- [Resend alternative](https://scribase.com/resend-alternative)
- [Send email from Next.js](https://scribase.com/mail/send-email-nextjs)
- [Send email from Python](https://scribase.com/mail/send-email-python)