# Migration from SendGrid

Move transactional sends from SendGrid to Groundmail. Receipts, password resets, alerts and invites still go out over `POST /emails`, with a simpler JSON body than SendGrid's v3 mail send payload.

**Import your SendGrid account (Beta).** Paste a SendGrid API key on the [Import page](https://app.groundmail.dev/import?provider=sendgrid) and Groundmail imports your suppressions, templates and sending domains. Nothing changes in your SendGrid account, and the key is never stored. Webhooks come over when you import from the terminal or the API.

**Or from the terminal**

```bash
export SENDGRID_API_KEY=…
groundmail migrate sendgrid --dry-run   # preview
groundmail migrate sendgrid             # import
```

Groundmail brings over your **suppressions** (bounces, complaints, unsubscribes), **templates** (variables converted), **sending domains** (with the DNS records to publish, one click on Cloudflare, Vercel and GoDaddy) and, from the terminal or the API, **webhooks** (events mapped, created disabled until your handler is ready). You get a summary of what came across and what needs attention, the send-code change for your stack, and a prompt for your coding agent. Details: [Import from another provider](https://docs.groundmail.dev/migrations).

After the import, the Import page keeps a **switch checklist** for your workspace: verify your domains, send a test, point your app at Groundmail, then a cutover check on the last 24 hours of sending. Each domain gets the exact DNS changes against what it publishes today: Groundmail's include goes into your existing SPF record (never a second SPF record), your DMARC record stays, and the rest are new records.

**Keep your SendGrid DNS records while you switch.** Leave the `s1._domainkey` and `s2._domainkey` CNAMEs and the `em…` CNAME in place: they use different names from Groundmail's, so mail from both keeps passing DKIM while your app moves over. Remove them, and `include:sendgrid.net` from SPF, a few days after the cutover. The import report (what came across, what was skipped and why) downloads as CSV from the Import page or with `groundmail migrate report <id> --csv`.

Sending a lot of mail? **We'll do it for you** on the Import page asks our team to run the switch with you.

The rest of this page is the same move by hand, field by field.

---

## Why teams switch

- **Straightforward HTTP API** — one `POST /emails` instead of nested `personalizations` / `content` arrays
- **Owned transactional mail infrastructure**, separate from cold/outbound reputation
- **Free → pay as you go → Dedicated**: test for free, run production on our shared transactional network, move to your own managed servers and IPs when you need allowlists

---

## Quick mapping

| SendGrid | Groundmail |
|----------|--------------|
| `SG.` API key | `gm_…` API key (`Authorization: Bearer`) |
| `https://api.sendgrid.com/v3/mail/send` | `https://api.groundmail.dev/emails` |
| `personalizations[].to[]` | `to` (string or array) |
| `from.email` + `from.name` | `from` (single address string) |
| `content[]` with `type` / `value` | `html` and/or `text` |
| Dynamic templates (`template_id`) | Template `alias` on send |
| Event Webhook | Webhooks + dashboard activity |
| ASM / unsubscribe groups | Managed unsubscribe; imported group unsubscribes become product email opt-outs |

---

## Minimal send

**SendGrid (v3):**

```bash
curl -X POST https://api.sendgrid.com/v3/mail/send \
  -H "Authorization: Bearer $SENDGRID_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "personalizations": [{ "to": [{ "email": "user@example.com" }] }],
    "from": { "email": "you@yourdomain.com" },
    "subject": "Hello",
    "content": [{ "type": "text/html", "value": "<p>It works.</p>" }]
  }'
```

**Groundmail:**

```bash
curl -X POST https://api.groundmail.dev/emails \
  -H "Authorization: Bearer $GROUNDMAIL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "you@yourdomain.com",
    "to": "user@example.com",
    "subject": "Hello",
    "html": "<p>It works.</p>"
  }'
```

---

## Node.js

**SendGrid:**

```ts
import sgMail from '@sendgrid/mail'
sgMail.setApiKey(process.env.SENDGRID_API_KEY!)
await sgMail.send({
  to: 'user@example.com',
  from: 'you@yourdomain.com',
  subject: 'Hello',
  html: '<p>It works.</p>',
})
```

**Groundmail:**

```ts
import { Groundmail } from 'groundmail'

const client = new Groundmail(process.env.GROUNDMAIL_API_KEY!)
await client.emails.send({
  from: 'you@yourdomain.com',
  to: 'user@example.com',
  subject: 'Hello',
  html: '<p>It works.</p>',
})
```

---

## Webhooks

SendGrid Event Webhook posts JSON arrays of events. Groundmail sends one signed JSON object per delivery with `Groundmail-Signature` (HMAC-SHA256). Map event names as follows:

| SendGrid event | Groundmail |
|----------------|--------------|
| `processed` | `email.sent` |
| `delivered` | `email.delivered` |
| `deferred` | `email.delivery_delayed` |
| `bounce` | `email.bounced` and `email.failed` (`bounce_type` says `hard` or `block`) |
| `dropped` | `email.failed` or `email.suppressed` |
| `open` | `email.opened` |
| `click` | `email.clicked` |
| `spamreport` | `email.complained` |

Use **Send test event** on the dashboard webhooks page (or `POST /emails/test`) to verify your handler before cutover.

---

## Checklist

1. Create a Groundmail API key (`gm_…`)
2. Add and verify your sending domain (SPF, DKIM, return-path)
3. Swap the client to `api.groundmail.dev` and map fields per table above
4. Recreate webhook endpoints and update signature verification
5. Send from Sandbox, then production after domain verify

---

## Compare

Marketing overview: [SendGrid alternative](https://groundmail.dev/compare/sendgrid/).
