0.6.16 • Published 8 months ago

@uscreen.de/postal-mailer v0.6.16

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

postal-mailer

Test CI Test Coverage Known Vulnerabilities NPM Version

Mailer engine using mjml templates to send mail via postal api or smtp

Features

  • configure inline (json object) or by dotenv
  • uses handlebars + mjml for compilation and render
  • sends mails via postal api or smtp

Install

$ yarn add @uscreen.de/postal-mailer # or use npm -i

Example

const mailer = require('@uscreen.de/postal-mailer')({
  // load config defaults from .env file (defaults to false)
  useDotenv: true,

  // override with inline options if needed
  postalSender: 'domains+noreply@postal-stage.uscreen.net'
})

const result = await mailer
  .sendMail({
    data,
    template: 'test',
    to: 'rcpt@example.com',
    subject: 'Example Test Mail'
  })
  .then(r => {
    console.log('RESULT:', r)
  })
  .catch(e => {
    console.error('ERROR sending mail:', e)
  })

Template

Please refer to https://mjml.io and https://handlebarsjs.com. Start with example like so:

<mjml>
  <mj-head>
    <mj-title>Test Mail</mj-title>
    <mj-attributes>
      <mj-all font-family="BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;"></mj-all>
      <mj-text font-weight="300" font-size="16px" color="#000000" line-height="24px"></mj-text>
    </mj-attributes>
  </mj-head>

  <mj-body background-color="#F2F2F2">

    <mj-section background-color="#ff781e" padding="20px">
      <mj-column width="100%">
        <mj-text align="center" font-size="24px" color="#ffffff" font-weight="600">
          A very simple Test E-Mail
        </mj-text>
      </mj-column>
    </mj-section>

    <mj-section background-color="#FFFFFF" padding="40px 20px">
      <mj-column width="100%">
        <mj-text>
          Greetings {{user.firstName}} {{user.lastName}},<br>
          <br>
          this is a simple example on how to setup a template and pass in some data.
        </mj-text>
        <mj-text>
          template will prefix all asset urls (ie. imgages) with<br>"{{postalAssetsUrl}}"
        </mj-text>
      </mj-column>
    </mj-section>

    <mj-section padding="0px 0 20px 0">
      <mj-column>
        <mj-text align="center" color="#9B9B9B" font-size="11px">ACME Inc, Street. 1, 12345 City</mj-text>
      </mj-column>
    </mj-section>

  </mj-body>
</mjml>

which renders to something like this:

npm.io

Options

All options can be managed via .env file and/or inline configuration as seen above. Overview of options:

optionDescriptionDefaultExample
useDotenvwhether to also read options from .env filesfalsetrue
postalTransportSend mail via Postal API or SMTPpostalsmtp
postalServerPostal Server Hostpostal.example.com
postalPortIf sending via SMTP, the SMTP port2525
postalUserIf sending via SMTP, the SMTP usernameacme/my-api
postalKeyIf sending via Postal API, the API Key to use. If sending via SMTP, the SMTP passwordExAmPlE_key
postalSenderFrom Address in emailsnoreply@example.com
postalTemplatespath to directory containing email templates<cwd>/templates./templates/mails
postalAssetsUrlurl to prefix assets''https://www.example.com/mail/assets
postalDefaultLocalewhen set, locales will default to 'en' and templates will default ./templates/en instead of ./templates'''en'

API

mailer.sendMail({ template, data, to, subject, locale = '' })

Send a template rendered with data to a recepient with a subject. (In an optional language set by locale)

Roadmap

Changelog

0.6.0

  • added smtp example
  • fixed pending upgrades

0.5.0

  • added support of attachments
  • added smtp transport

0.2.0

  • added (optional) multilanguage support for templates
  • added examples and docs

0.1.0

  • rendering of templates (to html + text) & sending thru api works
0.6.16

8 months ago

0.6.15

1 year ago

0.6.14

1 year ago

0.6.13

2 years ago

0.6.12

2 years ago

0.6.11

2 years ago

0.6.10

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.3-rc1

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago