Opens browser with email preview by rendering HTML file using bundled EJS template.
Email example from React Email
npm install email-viewer
Here is an example of how to use the viewEmail
function:
const message = {
subject: "test subject",
text: "Hello, world!",
}
if (process.env.NODE_ENV === "development") {
return import("email-viewer").then(({ viewEmail }) => viewEmail(message))
}
The viewEmail
function accepts an object with the following properties:
Property | Type | Description | Default |
---|---|---|---|
id | string |
ID of the email. If not provided, a random UUID will be generated. | randomUUID() |
dir | string |
Directory where the HTML file will be saved. If open is set to false, the file will not be created. | os.tmpdir() |
open | boolean |
Whether to automatically open the rendered HTML file in the default browser. | true |
subject | string |
Subject of the email. | undefined |
from | string |
Sender of the email. | undefined |
to | string | string[] |
Recipient(s) of the email. | undefined |
html | string |
HTML content of the email. | undefined |
text | string |
Plain text content of the email. | undefined |
The viewEmail
function returns an object with the following properties:
Property | Type | Description |
---|---|---|
id | string |
ID of the email. |
html | string |
Rendered HTML content. |