npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loopback-connector-postmark

v1.1.0

Published

Strongloop Loopback connector for Postmark (email sender)

Downloads

9

Readme

loopback-connector-postmark

npm version Loopback Postmark code style: prettier dependencies devDependencies

Strongloop Loopback connector for Postmark (email sender). Unofficial.

It uses wildbit/postmark.js under the hood. API can be found here.

Installation

npm install loopback-connector-postmark --save

Configuration

Add to datasources.json:

Configure a data source with a connector. All additional settings will go here.

"postmark": {
  "name": "postmark",
  "connector": "loopback-connector-postmark",
  "serverToken": "xxxx-xxxxx-xxxx-xxxxx-xxxxxx",
}

:point_up: Postmark lets you send emails only if you have a server token.

Please note: You can use the datasources.ENV.js version for configuration as well. Which sounds like quite a good idea for storing secrets:

'use strict';

module.exports = {
  postmark: {
    name: "postmark",
    connector: "loopback-connector-postmark",
    serverToken: process.env.POSTMARK_SERVER_TOKEN
  }
};

Add to model-config.json:

Bind loopback's built in Email model with the previously added data source.

"Email": {
  "dataSource": "postmark",
  "public": false
},

Usage

After a successful configuration, we have our postmark data source/connector bound with the Email model. So we use it as usual:

const loopback = require('loopback');

loopback.Email.send({
  // Required fields
  To: "[email protected]",
  From: "[email protected]",
  Subject: "subject",
  
  // Optional fields
  HtmlBody: "html is <strong>strong</strong>",
  TextBody: "text is cool as well",
  Cc: "[email protected]",
  Bcc: "[email protected]",
  ReplyTo: "[email protected]",
  Tag: "tag",
  TrackOpens: true,
  TrackLinks: true,
  Headers: { 
    ohMy: "header" 
  }
});

For fields not stated above, check Postmark's documentation. The whole object argument is just passed to the postmark client.

Usage with emails send by Loopback

Some of the emails are sent by Loopback itself. Unfortunately, it's not easy to override these methods and change the way they pass arguments to the Email.send() method.

This package tries to work around that.

User verify email

If you followed Loopback's documentation about verifying users email address you probably ended up with userInstance.verify(verifyOptions) method and verifyOptions something as follows:

let verifyOptions = {
  type: 'email',
  to: userInstance.email,
  from: '[email protected]',
  subject: 'Thanks for registering.',
  template: path.resolve(__dirname, '../../server/views/verify.ejs'),
  redirect: '/verified',
  user: userInstance
};

This package lets you configure that by adding verifyUserEmail object to postmark configuration object stored in datasources.json.

"postmark": {
  "name": "postmark",
  "connector": "loopback-connector-postmark",
  "serverToken": "xxxx-xxxxx-xxxx-xxxxx-xxxxxx",
  "verifyUserEmail": {
    "TemplateId": "[TEMPLATE_ID]",
    "name": {
      "from": "user.username"
    },
    "product_name": "My awesome product",
    "action_url": {
      "from": "verifyHref"
    },
    "login_url": "https://myawesomeproduct.com/app/login",
    "email": {
      "from": "user.email"
    },
    "support_email": "[email protected]",
    "sender_name": "John Doe",
    "company_name": "Awesome Product LTD"
  }
}

Provide TemplateId you use for the confirmation email in Postmark and the variables that you specified there. If you would like to dynamically copy values from verifyOptions, for example from user: userInstance object, then use an object with from property to point the path to the value you'd like to copy.

For example, if you have name variable in your template and you passed user: userInstance in your verification method then most probably the path to user's name is user.username:

"name": {
  "from": "user.username"
}