2.0.7 • Published 8 years ago

loopback-connector-sendgrid-musghost v2.0.7

Weekly downloads
4
License
MIT License (MIT)
Repository
github
Last release
8 years ago

loopback-connector-sendgrid

view on npm npm module downloads per month Dependency status Build Status Code
Climate Test Coverage

Loopback connector module which allow to send emails via SendGrid

Installation

npm install loopback-connector-sendgrid --save

Configuration

Sendgrid API key

Use the following configuration if you have an api key.

datasources.json

{
    "sendgrid": {
        "connector": "loopback-connector-sendgrid",
        "api_key": '[your api key here]'
    }
}

model-config.json

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

Configuration in JavaScript

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

Sendgrid settings

Using sendgrid mail_settings and tracking_settings: datasources.json

{
    "sendgrid": {
        "connector": "loopback-connector-sendgrid",
        "api_key": '[your api key here]',
        "mail_settings": {[your mail_settings JSON object]},
        "tracking_settings": {[your tracking_settings JSON object]}
    }
}

Usage

Basic option same as built in Loopback:

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

Advanced options using the sendGridConfig option:

loopback.Email.send({
    to: "test@to.com",
    from: "test@from.com",
    subject: "subject",
    text: "text message",
    html: "html <b>message</b>",
    sendGridConfig: {
        personalizations: ...,
        template_id: ...,
        sections: ...,
        headers: ...,
        categories: ...,
        custom_args: ...,
        send_at: ...,
        batch_id: ...,
        asm: ...,
        ip_pool_name: ...,
        reply_to: ...
    }
},
function(err, result) {
    if(err) {
        console.log('Upppss something crash');
        return;
    }
    console.log(result);
});

API

documented by jsdoc-to-markdown.

Changelog

License

MIT License (MIT). All rights not explicitly granted in the license are reserved.

Copyright (c) 2015 John Barry

Dependencies

loopback-connector-sendgrid@2.0.2 - "MIT License (MIT)", documented by npm-licenses.

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago