JSPM

mailik

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q9349F
  • License MIT

Send mail from templates

Package Exports

  • mailik

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mailik) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Mailik

Mailik is a ecosystem for send mail in your app :

  • Send mail with nodemailer
  • Template HTML with mjml
  • html, text and subject is a template with handlebars

Exemple

Prepare templates :

Html version :

invoice.mjml

<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-text><h1>Hello {{name}}</h1></mj-text>
        <p>You'r Invoice :</p>
        <mj-table>
          {{#each products}}
          <tr>
            <td>{{name}}</td>
            <td>{{price}}€</td>
          </tr>
          {{/each}}
        </mj-table>
        <mj-text>
          <p>Total : <strong>{{total}}€</strong></p>
        </mj-text>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>

Text version :

invoice.text

Hello {{name}}

You'r Invoice :

{{#each products}}
- {{name}} : {{price}}€
{{/each}}

Total : {{total}}€

Subject of mail :

invoice.subject

{{name}}, you'r invoice is ready ;)

On start of you'r app, init mailik with you'r config :

const path = require('path')
const mailik = requrie('mailik')

mailik.init({
  directory: path.join(__dirname, './templates'),
  mail: {
    /* default config for mail */
    from: 'John Doe <admin@exemple.com>',
  },
  nodemailer: {
    /* nodemailer transport config */
    host: 'smtp.domain.com',
    port: 25,
    auth: {
      user: 'xxxxxxxxxxxxxxxx',
      pass: 'xxxxxxxxxxxxxxxx',
    },
  },
})

And use

const mailik = require('mailik')

const invoiceMail = mailik('invoice') // template name

invoiceMail('to@exemple.com', {
  name: 'Simon',
  products: [
    { name: 'Product A', price: 42 },
    { name: 'Product B', price: 4242 },
  ],
  total: 4284,
})
  .then((infos) => {
    console.log(infos)
  })
  .catch((err) => {
    console.error(err)
  })

Directory

All templates must has 3 versions :

  • .subject
  • .text
  • .mjml if you use MJML, or .html
  • /templates/directory/[nameOfTemplate].mjml
  • /templates/directory/[nameOfTemplate].text
  • /templates/directory/[nameOfTemplate].subject

Exemples :

  • /templates/directory/welcome.mjml
  • /templates/directory/welcome.text
  • /templates/directory/welcome.subject
  • /templates/directory/forgetPassword.mjml
  • /templates/directory/forgetPassword.text
  • /templates/directory/forgetPassword.subject
  • /templates/directory/youHaveAMessage.mjml
  • /templates/directory/youHaveAMessage.text
  • /templates/directory/youHaveAMessage.subject