apps/docs/cli.mdx
email devStarts a local development server that will watch your files and automatically rebuild your email template when you make changes.
Options
<ResponseField name="--dir" type="string" default="emails"> Change the directory of your email templates. </ResponseField> <ResponseField name="--port" type="string" default="3000"> Port to run dev server on </ResponseField>F.A.Q
<AccordionGroup> <Accordion title="Where can I place my static files for previewing?"> Almost always you will need to have static files in your emails, and seeing them on the preview server without having to first host on a CDN is very helpful.We do allow for this, and currently, you can place your files inside a `static`
directory inside your `emails` directory.
This does adjust to your `--dir` option, so if your `emails` directory was inside
`./src/emails`, you would place your static files inside `./src/emails/static`.
These static files are directly served from our preview server by looking into the
requests made into it that end with `/static` (i.e. `http://localhost:3000/static/...`) and serving the files at that point,
this also allows for you to have images inside your emails like so:
```jsx
export default function Email(props) {
return (
<div>
</div>
);
}
```
<Info>
This does not mean your images are hosted for you to send the emails.
If you do send the rendered email, and you are trying to link to an image,
or some other asset inside `emails/static`, they will not load on the email that was sent.
We recommend that you use a different source link to your files depending on whether you're
running in production or not. Here's an example
```jsx
const baseURL = process.env.NODE_ENV === "production" ? "https://cdn.com" : "";
export default function Email(props) {
return (
<div>
</div>
);
}
```
You can refer to our [demo emails source code](https://demo.react.email/preview/notifications/vercel-invite-user)
for an example of how we do this with our demo deploy on Vercel.
</Info>
```jsx Email template
export default function Email(props) {
return (
<div>
<a href={props.source}>click here if you want candy 👀</a>
</div>
);
}
Email.PreviewProps = {
source: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
};
```
And then, when opening this email's preview, the `PreviewProps` will be used as props into Email.
So, in a nutshell, it will render the same as if you were to do:
```jsx Another file
import Email from "./path-to-my-email";
<Email {...Email.PreviewProps} />;
```
So if you wanted to make components for your emails, you could have a file structure as follows:
```bash
my-project
├── emails
│ ├── _components
│ │ └── this-is-not-going-to-appear-in-the-sidebar.tsx
│ ├── email.tsx
│ └── static
├── package.json
└── tsconfig.json
```
Then the only file that will be shown on the preview server is going to be your `email.tsx`.
1. If a file has `.js, .jsx or .tsx` as their file extension
2. If the file contains a `export default` expression by matching with the regex
`/\bexport\s*default\b/gm`
These can certainly fail as they are only heuristics, so if you do find
any issues with these, feel free to open an [issue](https://github.com/resend/react-email/issues).
email buildCopies the preview app for onto .react-email and builds it.
email startRuns the built preview app that is inside .react-email.
email exportGenerates the plain HTML files of your emails into a out directory.
The primary and preferable way is always going to be the render utility, by passing in the needed data through props, on the exact moment of sending the email.
email export is a secondary way meant for situations where React Email cannot be used optimally.
With this secondary way, comes significant drawbacks, mainly the need for manual templating, which
could be done easily with the render utility. It being a secondary way, we would strongly recommend
you don't use it unless you really are forced into it.
As an example, two cases where email export makes itself necessary include:
You also should not have to worry about render's performance, as typically, the introduced
time in rendering is going to be milliseconds when compared to manual templating.
</Info>
Options
<ResponseField name="--outDir" type="string" default="out"> Change the output directory. </ResponseField> <ResponseField name="--pretty" type="boolean" default="false"> Minify or prettify the generated HTML file. </ResponseField> <ResponseField name="--plainText" type="boolean" default="false"> Set output format as plain text. </ResponseField> <ResponseField name="--dir" type="string" default="emails"> Change the directory of your email templates. </ResponseField>email help <cmd>Shows all the options for a specific command.
email resend setupSets up a configuration in your home directory with your Resend API Key by prompting interactively.
email resend resetRemoves your API Key from the configuration in your home directory.