https://github.com/oreqr/email-viewer
📧Opens browser with email preview
https://github.com/oreqr/email-viewer
automation devtool email mail mailer nodejs nodemailer preview smtp viewer
Last synced: 7 months ago
JSON representation
📧Opens browser with email preview
- Host: GitHub
- URL: https://github.com/oreqr/email-viewer
- Owner: OreQr
- License: mit
- Created: 2024-06-26T12:14:16.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-20T11:47:22.000Z (over 1 year ago)
- Last Synced: 2024-11-20T12:43:38.540Z (over 1 year ago)
- Topics: automation, devtool, email, mail, mailer, nodejs, nodemailer, preview, smtp, viewer
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/email-viewer
- Size: 120 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Email viewer



[](https://github.com/prettier/prettier)
Opens browser with email preview by rendering HTML file using bundled EJS template.
## Preview
Email example from [React Email](https://react.email)

## Installation
```bash
npm install email-viewer
```
## Example usage
Here is an example of how to use the `viewEmail` function:
```typescript
const message = {
subject: "test subject",
text: "Hello, world!",
}
if (process.env.NODE_ENV === "development") {
return import("email-viewer").then(({ viewEmail }) => viewEmail(message))
}
```
## Options
The `viewEmail` function accepts an object with the following properties:
### ViewEmailOptions
| 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` |
## Result
The `viewEmail` function returns an object with the following properties:
### ViewEmailResult
| Property | Type | Description |
| -------- | -------- | ---------------------- |
| id | `string` | ID of the email. |
| html | `string` | Rendered HTML content. |
## License
[MIT](https://github.com/OreQr/email-viewer/blob/main/LICENSE.txt)