svelte-mail
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

svelte-mail

Renders Svelte components for emails. Inlines styles and renders additional plain text version.

CircleCI

Installation

Run npm i --save svelte-mail.

Usage

Simply pass a Svelte component and some options:

./components/Mail.svelte

<script>export let user;</script> 
 
<style>strong { color: red }</style> 
 
<strong>Hello, {user}</strong>

./sendMail.js

import { renderMail } from 'svelte-mail';
import Mail from './components/Mail.svelte';
 
async function sendMail() {
  const { html, text } = await renderMail(Mail, { data: { user: 'World' } });
 
  /*
    `html` contains the rendered html string:
    "<strong style="color: red">Hello, World</strong>"
 
    `text` contains the rendered plain text message:
    "Hello, World"
  */
 
  // TODO: Send mail, e.g. using nodemailer...
}
 
sendMail()
  .catch(console.error);

Note: The mail component must be compiled for server side rendering.

Options

Internally, this module uses juice to inline styles and html-to-text to render plain text messages. All options passed to the renderMail function will be passed to them:

renderMail(Mail, {
  data: {},
  // add any juice options here, e.g.:
  extraCss: 'strong { text-decoration: underline }',
  // add any html-to-text options here, e.g.:
  uppercaseHeadings: false,
});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    42
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    42

Package Sidebar

Install

npm i svelte-mail

Weekly Downloads

42

Version

0.1.1

License

MIT

Unpacked Size

16.8 kB

Total Files

21

Last publish

Collaborators

  • lhechenberger