<!-- Markdown twin of https://pixelvault.dev/docs/guides/email-images/ -->

# Images in email (Resend / react-email)

**Goal:** every image in your transactional email renders in Gmail and Outlook. Gmail doesn't render base64 `data:` images and many Outlook clients don't either, so every image in an email has to point at a public URL. Resend sends the email but doesn't host images, so host them on PixelVault first and reference the returned URL. PixelVault returns a stable, immutable CDN URL with no fixed expiry and zero egress fees. Free-plan retention still applies; paid plans retain images indefinitely.

```
npm install resend @react-email/components @react-email/render
export PIXELVAULT_API_KEY=...   # secret key, server-side only
export RESEND_API_KEY=...
npx tsx prep.ts                 # prints the logo URL once
```

## 1\. A hosting helper

A tiny helper uploads a local asset and hands back the CDN URL (server-side — it uses your secret API key):

```
// email-images.ts — host a local asset once, get a stable CDN URL with no fixed expiry.
import { readFile } from "node:fs/promises";
import { basename } from "node:path";

const API = "https://api.pixelvault.dev/v1/images";

export async function hostForEmail(path: string): Promise<string> {
  const form = new FormData();
  form.append("file", new Blob([await readFile(path)]), basename(path));

  const res = await fetch(API, {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.PIXELVAULT_API_KEY}` },
    body: form,
  });
  if (!res.ok) throw new Error(`PixelVault upload failed: ${res.status}`);

  const { data } = await res.json(); // the URL is nested under `data`
  return data.url; // https://img.pixelvault.dev/proj_xyz789/img_abc123.png
}
```

## 2\. Host each asset once

The URL has no fixed expiration, so host each asset **once** — a prep script or CI step — and save the URL (an env var works). Don't call this per send, or you'll mint a new URL and burn an upload every time:

```
// prep.ts — run ONCE (a script or CI step). The URL has no fixed expiry,
// so host the asset a single time and save the URL, e.g. to an env var.
import { hostForEmail } from "./email-images";

const logoUrl = await hostForEmail("./assets/logo.png");
console.log(logoUrl); // → store as EMAIL_LOGO_URL; never re-host per send
```

## 3\. Use it in the template

Pass that saved URL into your [react-email](https://react.email) template as a prop and render it with `<Img>`. Serve a 2× image and constrain it with `width` for crisp retina — the [transform params](/docs/transforms/) resize on the fly:

```
// receipt.tsx — the hosted URL comes in as a prop (no per-render upload).
import { Img } from "@react-email/components";

export function Receipt({ logoUrl }: { logoUrl: string }) {
  // Serve at 2× (w=240), display at 120 — crisp on retina.
  return <Img src={`${logoUrl}?w=240&fmt=auto`} width="120" alt="Acme" />;
}
```

## 4\. Send

Then render the template to HTML and send it (this file is `.tsx` — it contains JSX):

```
// send.tsx — render with the pre-hosted URL and hand the HTML to Resend.
import { Resend } from "resend";
import { render } from "@react-email/render";
import { Receipt } from "./receipt";

const resend = new Resend(process.env.RESEND_API_KEY);
const logoUrl = process.env.EMAIL_LOGO_URL!; // hosted once, saved earlier

await resend.emails.send({
  from: "receipts@yourdomain.com",
  to: "customer@example.com",
  subject: "Your receipt",
  html: await render(<Receipt logoUrl={logoUrl} />),
});
```

Hosting images well makes them **render** reliably and keeps egress flat — it doesn't affect deliverability. Inbox placement depends on your sending domain and SPF/DKIM/DMARC: Resend provides the authentication tooling, but the DNS and list hygiene are yours.

Not on react-email? The same idea works with any templating: call `hostForEmail()` once, save the URL, then interpolate it into your `<img src>`.

## Next steps

-   [Full walkthrough](/blog/host-images-in-resend-emails/) with Resend.
-   [Image transforms](/docs/transforms/) for sizes and formats.
-   [Generate a header image](/docs/guides/generate-images/) from a prompt.
