0.0.2 • Published 13 years ago

postage v0.0.2

Weekly downloads
1
License
-
Repository
github
Last release
13 years ago

postage

node.js module for PostageApp API Client


Installation:

$ 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"
      }
    }
  }
}