node package manager

postage

postage

node.js module for PostageApp API Client


Installation:

The recommended way is through npm:

$ npm install postage

Sending a Message

var postage = require('postage')('YOUR API KEY');
  
var options = { 
  recipients: 'email@address.com',
  subject: 'Subject Line',
  from: 'sender@example.org',
  content: {
    'text/html': '<h1>Some awesome content</h1>',
    'text/plain': 'Plain text goes here (if any)'
  }
};
 
postage.send(options, function callback(error, msg) {
  if (error) {
    console.error(error);
  } else {
    console.log(message);
  }
});

alternatively you can use templates (which are setup on postageapp.com)

var options = {
  recipients: 'email@address.com',
  subject: 'Subject Line',
  from: 'sender@example.org",
  templates: 'my_template',
  variables: {
    variable1: 'value',
    variable2: 'value2
  }
};

sending the message to multiple recipients

var options = {
  recipients: ['email@address.com', 'email2@address2.com']
};

sending the message to multiple recipients with variable data

recipients: {
  "email@example.com": {
    'variable': 'Value'
  }, 
  "email2@example.com": {
    'variable': 'Value2'
  }
};

Response will look like

{ "response" : {
  "uid" : ResponseUID,
    "status" : ok
  },
  "data" : {
    "message” : {
      "id" : "DataID"
    }
  }
}

Retrieving a Message Recept by UID

var postage = require('postage')(key);
 
postage.get_message_receipt('some-uid-key', function(error, message) {
  if (error) {
    console.error(error);
  } else {
    console.log(message);
  }
});

response

{ "response" : {
    "uid" : "uid_of_the_message",
    "status" : "ok"
  },
  "data" : {
    "message" : {
      "id" : "1234567890"
    }
  }
}

Fetching Account Info

var postage = require('postage')(key);
 
postage.get_account_info(function(error, message) {
  if (error) {
    console.error(error);
  } else {
    console.log(message);
  }
});

response

{"response":
  {
    "status":"ok",
    "uid":1333844159296
  },
  "data":{
    "account":{
      ...
    }
  }
}

Get Method List (List Available API Methods)

var postage = require('postage')(key);
 
postage.get_method_list(function(error, message) {
  if (error) {
    console.error(error);
  } else {
    console.log(message);
  }
});

response

{ response: { 
    status: 'ok',
    uid: null
  },
  data: { 
    methods: 'get_account_info, get_message_receipt, get_method_list, get_metrics, get_project_info, message_delivery_status, message_status, send_message, test_mail_server, test_recipient'
  } 
}

Get Project Info

var postage = require('postage')(key);
 
postage.get_project_info(function(error, message) {
  if (error) {
    console.error(error);
  } else {
    console.log(message);
  }
});

response

{ "response" : {
    "status" : "ok",
    "uid" : nil
  },
  "data" : {
    "project" : {
      "name" : "Project Name",
      "url" : "account-name.postageapp.com/projects/12345",
      "transmissions" : {
        "today" : "12345",
        "this_month" : "123456",
        "overall" : "1234567"
      },
      "users" : {
        "user_1@example.com" : "User Name 1",
        "user_2@example.com" : "User Name 2"
      }
    }
  }
}

Authors and Contributors

Maintained by unfolio
Edward H. Hotchkiss(@edwardhotchkiss) and Kevin Sakhuja(@kevbook).


MIT License

Copyright © 2012 unfolio

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.