lb-connector-sendcloud

    0.2.0 • Public • Published

    lb-connector-sendcloud

    lb-connector-sendcloud is the Loopback connector module which allow to send emails via Mandrill.

    1. Installation

    npm install lb-connector-sendcloud --save

    2. Configuration

    datasources.json

    {
        "sendcloud": {
            "connector": "lb-connector-sendcloud",
            "apiUser": "[your api user here]",
            "apiKey": "[your api key here]"
        }
    }

    model-config.json

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

    Additionaly you can set defaults

    {
        "sendcloud": {
            "connector": "lb-connector-sendcloud",
            "apiUser": "[your api user here]",
            "apiKey": "[your api key here]",
            "defaults": {
            }
        }
    }

    Configuration in JavaScript

    var DataSource = require('loopback-datasource-juggler').DataSource;
    var dsSendcloud = new DataSource('lb-connector-sendcloud', {
         "apiUser": "[your api user here]",
         "apiKey": "[your api key here]"
    });
    loopback.Email.attachTo(dsSendcloud);

    3. Use

    Basic option same as built in Loopback

    loopback.Email.send({
        to: "test@to.com",
        from: "test@from.com",
        subject: "subject",
        text: "plain text message",
        html: "html <b>message</b>"
    },
    function(err, result) {
        if(err) {
            console.log('Upppss something crash');
            return;
        }
        console.log(result);
    });

    Some advantages - now you can use templates from Sendcloud

    loopback.Email.send({
        to: "test@to.com",
        from: "test@from.com",
        subject: "subject",
        template: {
            name: "signup-confirm"
        }
        contentSummary: 'the summary of your content'
        labelId: "123456"
    },
    function(err, result) {
        if(err) {
            console.log('Upppss something crash');
            return;
        }
        console.log(result);
    });

    To customize emails using vars

    Single Recipient

    var
      params,
      user = {
        firstName: 'Paul',
        email: 'paul@example.com'
      }
      
      params = {
        to: user.email,
        template: {
          name: 'test-email',
        }
        ,vars: [
            //in your sendcloud template `*|FIRST_NAME|*`
            {
              name: 'FIRST_NAME',
              content: user.firstName
            }
          ]
      };
      
      loopback.Email.send( params, function( err, email ) {
          ...
      })

    Multiple Recipients

    var
      params,
      users = [
        {
          firstName: 'Kaitlin',
          email: 'kaitlin@example.com'
        },
        {
          firstName: 'Ryan',
          email: 'ryan@example.com'
        }
      ];
     
    params = {
      to: users.map( function( user ) {
        return user.email;
      }),   
      template: {
        name: 'test-email'
      },
      vars: {
            name: 'FIRST_NAME'
          }
    };
     
    loopback.Email.send( params, function( err, email ) {
        ...
    })

    Install

    npm i lb-connector-sendcloud

    DownloadsWeekly Downloads

    2

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • acte