Skip to content

Commit

Permalink
Merge pull request #2 from MadisonReed/moreMethods
Browse files Browse the repository at this point in the history
Many more methods
  • Loading branch information
scottspork committed Apr 9, 2014
2 parents 4d6ba17 + 12b579a commit 3dabf79
Show file tree
Hide file tree
Showing 3 changed files with 818 additions and 26 deletions.
338 changes: 338 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
# Postmark API

This is a full REST API wrapper for Postmark

To use the module, run `npm install postmarkapi`

## Using the module

First you must make a instance of the module, with your Postmark Server token.

```js
var PostmarkAPI = require('postmarkapi');
var pmk = new PostmarkAPI('[your server token]');
```

## Sending an email

You always need to define a `to` for an email, and `subject`. You can send `text` or `html`, or both, but you need to define one or ther other.

If you don't define a `from`, it will use the address you created the Sender Signature with.

You can send multiple `cc`s or `bcc`s by passing an array.

You don't need to pass a callback.

```js
// simple example
pmk.email({
to: '[email protected]',
subject: 'Test Email',
text: 'Hello World'
});

// more specific
pmk.email({
to: '[email protected]',
from: '[email protected]',
fromName: 'John Doe',
cc: ['[email protected]', '[email protected]'],
bcc: '[email protected]',
reply: '[email protected]',
tag: 'MyTag',
headers: {
EmailedUsing: 'Node PostmarkAPI Module'
},
subject: 'Test Email',
text: 'Hello World',
html: '<strong>Hello World</strong>'
}, function(err, response) {
// ...
});
```
You can also send an email with attachments

```js
var path = require('path');

pmk.email({
to: '[email protected]',
from: '[email protected]',
subject: 'Test Email',
text: 'Hello World',
html: '<strong>Hello World</strong>',
attachments: [
path.resolve(__dirname, 'cats.gif'),
path.resolve(__dirname, 'notes.txt')
]
}, function(err, response) {
// ...
});
```

## Bounces

### Getting a summary of bounces for the server

```js
pmk.deliverystats(function(err, response) {});
```

### Retrieving bounces

You can retrieve bounces associated with your server.

```js
// simple example
pmk.bounces({
count: 10,
offset: 0
}, function(err, response) {});

// with messageId
pmk.bounces({
messageId: '[messageIDHere]'
}, function(err, response) {});

// more sepcific
pmk.bounces({
count: 10,
offset: 0,
type: 'HardBounce',
inactive: 0,
emailFilter: 'somewhere.com'
}, function(err, response) {});
```

### Getting a list of tags for bounces on server

```js
pmk.bounceTags(function(err, response) {});
```

### Getting a single bounce

```js
pmk.bounce(bouncId, function(err, response) {});
```

### Getting a single bounce's dump

```js
pmk.bounceDump(bouncId, function(err, response) {});
```

### Activating a deactivated bounce

Callback optional

```js
pmk.bounceActivate(bounceId, function(err, response) {});
```

## Outbound messages

### Retrieving sent messages

```js
// simple example
pmk.outbound({
count: 10,
offset: 0
}, function(err, response) {});
```

```js
// more specific
pmk.outbound({
count: 10,
offset: 0,
recipient: '[email protected]',
fromemail: '[email protected]',
tag: 'MyTag',
subject: 'Welcome Email'
}, function(err, response) {});
```

### Getting details for a single sent message

```js
pmk.outboundMessage(messageId, function(err, response) {});
```

### Getting message dump

```js
pmk.outboundMessageDump(messageId, function(err, response) {});
```

## Inbound messages

### Retrieving recieved messages

```js
// simple example
pmk.inbound({
count: 10,
offset: 0
}, function(err, response) {});
```

```js
// more specific
pmk.inbound({
count: 10,
offset: 0,
recipient: '[email protected]',
fromemail: '[email protected]',
tag: 'MyTag',
subject: 'Welcome Email',
mailboxhash: 'mailboxhashvalue'
}, function(err, response) {});
```

### Gettings details for a single recieved message

```js
pmk.inboundMessage(messageId, function(err, response) {});
```

## Sender Signatures

### Getting a list of Sender Signatures

```js
pmk.senders({
count: 10,
offset: 0
}, function(err, response) {});
```

### Fetching details for a single sender

```js
pmk.sender(senderId, function(err, response) {});
```

### Creating a Sender Signature

The `reply` and callback are optional

```js
pmk.createSender({
name: 'Sender Name',
from: '[email protected]',
reply: '[email protected]'
}, function(err, response) {});
```

### Updating a Sender Signature

The `reply` and callback are optional

You cannot update the `from` address

```js
pmk.updateSender(senderId, {
name: 'Sender Name',
reply: '[email protected]'
}, function(err, response) {});
```

### Resending a Sender Signature confirmation email

The callback is optional

```js
pmk.resendSender(senderId, function(err, response) {});
```

### Deleting a Sender Signature

The callback is optional

```js
pmk.deleteSender(senderId, function(err, response) {});
```

### Verifying a SPF record

The callback is optional

```js
pmk.verifySPF(senderId, function(err, response) {});
```

### Requesting a new DKIM

The callback is optional

```js
pmk.requestDKIM(senderId, function(err, response) {});
```

## Servers

### Getting a list of servers

```js
pmk.servers({
count: 10,
offset: 0,
name: 'Production'
}, function(err, response) {});
```

### Getting a single server's details

```js
pmk.server(serverId, function(err, response) {});
```

### Creating a new server

```js
// simple example
pmk.createServer({
name: 'Server Name'
});

// more specific
pmk.createServer({
name: 'Server Name',
color: 'red',
smtp: true,
raw: true,
inboundHook: 'https://...',
bounceHook: 'https://...',
inboundDomain: 'myDomain'
}, function(err, response) {});
```

### Updating a server

```js
// simple example
pmk.updateServer(serverId, {
name: 'Server Name'
});

// more specific
pmk.updateServer(serverId, {
name: 'Server Name',
color: 'red',
smtp: true,
raw: true,
inboundHook: 'https://...',
bounceHook: 'https://...',
inboundDomain: 'myDomain'
}, function(err, response) {});
```

### Deleting a server

The callback is optional

```js
pmk.deleteServer(serverId, function(err, response) {});
```
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"node": ">=0.10.20"
},
"dependencies" : {
"request": "2.34.0"
"request": "2.34.0",
"mime": "1.2.11",
"async": "0.7.0"
},
"repository": "git://github.com/MadisonReed/postmarkapi"
}
Loading

0 comments on commit 3dabf79

Please sign in to comment.