Skip to content

Loopback connector module which allow to send emails via Sparkpost

Notifications You must be signed in to change notification settings

nidhhoggr/loopback-connector-sparkpost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loopback-connector-sparkpost

loopback-connector-sparkpost is the Loopback connector module which allow to send emails via Sparkpost.

1. Installation

npm install loopback-connector-sparkpost --save

2. Configuration

datasources.json

{
    "sparkpost": {
        "connector": "loopback-connector-sparkpost",
        "apiKey": "[your api key here]",
        "defaults": {
          "options": {
            "start_time": "now"
          }
        }
    }
}

model-config.json

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

Additionaly you can set defaults

{
    "sparkpost": {
        "connector": "loopback-connector-sparkpost",
        "apiKey": "[your api key here]",
        "defaults": {
          "content": {
            "from": { name: "Bob Schmoe", email: "[email protected]" }
          }
        }
    }
}

Configuration in JavaScript

var DataSource = require('loopback-datasource-juggler').DataSource;
var dsSparkpost = new DataSource('loopback-connector-sparkpost', {
    apiKey: '[your api key here]'
});
loopback.Email.attachTo(dsSparkpost);

3. Use

Basic option same as built in Loopback

loopback.Email.send({
    to: "[email protected]",
    from: "[email protected]",
    subject: "subject",
    text: "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 Sparkpost

loopback.Email.send({
    to: "[email protected]",
    from: "[email protected]",
    subject: "subject",
    template: {
        id: "signup-confirm",
        content: {
            name: "NewUser Name",
            accountId: "123456"
        }
    }
},
function(err, result) {
    if(err) {
        console.log('Upppss something crash');
        return;
    }
    console.log(result);
});

1. Testing

Be sure to test from one of the approved domains.

apiKey=hwgfhfhjgrfhjekjheiff [email protected] startTime=2016-09-30T17:55:11 mocha basic.test.js --timeout 15000

About

Loopback connector module which allow to send emails via Sparkpost

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published