Vue-letter is a Vue.js component designed for displaying HTML or plain text email messages within Vue applications. It functions as a direct port of the `react-letter` library, offering features like wrapping content in an iframe, rewriting external resource and link URLs, and specifying allowed URL schemas. The package helps developers render email bodies while addressing potential security and styling concerns. Currently at an early version (0.2.1), it is under active development, implying its API and features are still evolving. Its main purpose is to simplify the secure rendering of email content, particularly targeting rendering compatibility similar to Gmail's approach.
npm install vue-letterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates importing and using the `Letter` component to display HTML and plain text email content, including advanced props for iframe usage, link rewriting, and schema control.
Pin exact versions (e.g., `"vue-letter": "0.2.1"`) in `package.json` to prevent unexpected breaking changes on update. Regularly check the GitHub repository for updates and migration guides.
Always pre-sanitize untrusted HTML input using a robust, well-maintained library like `DOMPurify` before passing it to the `html` prop. Example: `import DOMPurify from 'dompurify'; const safeHtml = DOMPurify.sanitize(untrustedHtml);`
Carefully consider the trade-offs of using `useIframe`. If used, ensure robust CSS within the email content itself handles responsiveness, or implement post-load JavaScript to adjust iframe dimensions if necessary. Use the `iframeTitle` prop for accessibility.
Explicitly configure the `allowedSchemas` array to only include the minimum necessary URL schemes for your application's security policy. For example, to disallow `mailto`, remove it from the array.
Ensure `import { Letter } from 'vue-letter';` is present in your `<script setup>` block or in the component's script section. If not using `<script setup>`, register it globally with `app.component('Letter', Letter)` or locally in your component's `components` option.Verify that you are passing `html` and `text` props as `String` types, as specified in the component's attributes. Ensure your TypeScript setup correctly recognizes the `vue-letter` types. If you're on an older Vue/TypeScript version, updating might resolve the issue, or you might need to cast the prop type temporarily.