# Migrate from Resend to Scribase Mail

> Switch the resend SDK to Scribase Mail by changing one base URL and environment variable.

Source: https://scribase.com/mail/migrate-from-resend

## Change the base URL

```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>',
});
```

## Or just the environment variable

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

## Verify webhook signatures unchanged

```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');
}
```

## Test addresses

- delivered@test.scribase.dev
- bounced@test.scribase.dev
- complained@test.scribase.dev

## Send from Python

```python
import os
import requests

response = requests.post(
    "https://mail-api.scribase.com/emails",
    headers={"Authorization": f"Bearer {os.environ['SCRIBASE_MAIL_KEY']}"},
    json={
        "from": "Acme <hello@acme.com>",
        "to": ["you@example.com"],
        "subject": "It works",
        "html": "<p>Sent through Scribase Mail.</p>",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["id"])
```