sgrid

0.0.7 • Public • Published

Node-Sendgrid

Simple way of sending email using the sendgrid rest api

Installation

$ npm install node-sendgrid

Examples

var SendGrid = require('../')
  , Email = SendGrid.Email
  , Stats = SendGrid.Stats;

Use global settings

SendGrid.settings({
  api_user: 'sendgrid-username'
, api_key: 'sendgrid-password'
, from: 'default@example.com'
});

Get all Applications and the current settings for each.

SendGrid.getApps(function(err, data){
  if(err) return;
  data.forEach(function(app){
    SendGrid.getAppSettings(app.name , function(err, data){
      console.log(app.name + '\t' + app.title + '\t' + app.activated + '\n\t\t' + app.description);
      console.log(data);
    })
  })
});

Authentication without global settings

Email({ api_user: 'sendgrid-username', api_key: 'sendgrid-password'})

or

Email()
  .api_user('sendgrid-username')
  .api_key('sendgrid-password');

Simple email

Email()
  .to('user@domain.com')
  .from('server@host.com')
  .subject('Testing node-sendgrid')
  .text('nodejs rules')
  .send();

Same email different syntax

Email({
  to: 'user@domain.com'
, from: 'server@host.com'
, subject: 'Testing node-sendgrid'
, text: 'nodejs rules'
}).send();

Sample email with lots of options.

Email()
  .header('X-Mailer', 'nodejs')
  .phone('555-555-5555')
  .to('user@somewhere.com')
  .to('user2@somewhere.com')
  .bcc('me@here.com')
  .from('server@host.com')
  .fromname('Server Id')
  .replyto('info@host.com')
  .file('/path/to/file.txt')
  .category('test')
  .subject('a test email')
  .html('<h3>Hi!</h3>')
  .template(template)
  .subscription({
    'enable': true
  , 'text/html': "If you would like to unsubscribe and stop receiving these emails <% Click Here %>."
  , 'text/plain': "If you would like to unsubscribe and stop receiving these emails <% %>."
  , url: 'http://yoursite.com/unsubscribe'
  })
  .opentrack(false)
  .clicktrack(false)
  .bypass()
  .ganalytics(source, medium, campaign, term, content)
  .footer()
  .custom({'name': 'First', 'phone': '555-555-5555'})
  .send(function(err, data){
    console.log(err)
    console.log(data)
  });

Stats Examples

Stats()
  .days(30)
  .aggregate(true)
  .category('test')
  .send(function(err, data){
    console.log(data);
  })

Stats({days: 30, aggregate: true});

Stats({start_date: '2011-05-15', end_date: '2011-05-20'})

Stats()
  .start('2011-05-15')
  .end('2011-05-20')
  .aggregate()

Misc API

SendGrid.getProfile(fn)
SendGrid.setProfile(obj, fn)
SendGrid.setPassword(password, confirm, fn)
SendGrid.setUsername(username, fn)
SendGrid.setEmail(email, fn);

SendGrid.getBounces(fn);
SendGrid.deleteBounce(email, fn);

SendGrid.getInvalid(fn)
SendGrid.deleteInvalid(email, fn)

SendGrid.getSpamList(fn);
SendGrid.removeEmail(email, fn);

SendGrid.getUnsubscribesList(fn);
SendGrid.deleteUnsubscribesEmail(email, fn);
SendGrid.addUnsubscribeEmail(email, fn);

SendGrid.getEventUrl(fn);
SendGrid.setEventUrl(url, fn);
SendGrid.deleteEventUrl(fn);

SendGrid.getParse(fn);
SendGrid.setParse(hostname, url, spam, fn);
SendGrid.deleteParse(hostname, fn);

SendGrid.getApps(fn)
SendGrid.activateApp(name, fn)
SendGrid.deactivateApp(name, fn)
SendGrid.getAppSettings(name, fn);
SendGrid.setAppSettings(name, settings, fn);

SendGrid.whitelist(email, fn);
SendGrid.bcc(email, fn);

SendGrid.Newsletter.addTemplate(obj, fn);
SendGrid.Newsletter.editTemplate(obj, fn);
SendGrid.Newsletter.deleteTemplate(name, fn);

SendGrid.Newsletter.getContent(fn);
SendGrid.Newsletter.addContent(obj, fn);
SendGrid.Newsletter.editContent(obj, fn);
SendGrid.Newsletter.deleteContent(name, fn)

SendGrid.Newsletter.getLists(fn);
SendGrid.Newsletter.addList(title, obj, fn);
SendGrid.Newsletter.editList(title, newtitle, obj, fn);
SendGrid.Newsletter.deleteList(title, fn);


NewsLetter

Template.add();
Template.update();
Template.remove();

Content.add();
Content.update();
Content.remove();

List.add()
List.update()
List.remove()

Features

Authors

License

(The MIT License)

Copyright (c) 2010 Storify <dev@storify.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i sgrid

Weekly Downloads

8

Version

0.0.7

License

none

Last publish

Collaborators

  • storify
  • nw