Complete Postmark REST API wrapper
npm install postmarkapiThis is a full REST API wrapper for Postmark
To use the module, run npm install postmarkapi
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]');
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 ccs or bccs by passing an array.
You don't need to pass a callback.
`js
// simple example
pmk.email({
to: 'someaddress@somewhere.com',
subject: 'Test Email',
text: 'Hello World'
});
// more specific
pmk.email({
to: 'someaddress@somewhere.com',
from: 'fromaddress@somewhere.com',
fromName: 'John Doe',
cc: ['carbon-copy@somewhere.com', 'carbon-copy-2@somewhere.com'],
bcc: 'blind-carbon-copy@somewhere.com',
reply: 'reply-to@somewhere.com',
tag: 'MyTag',
headers: {
EmailedUsing: 'Node PostmarkAPI Module'
},
subject: 'Test Email',
text: 'Hello World',
html: 'Hello World'
}, function(err, response) {
// ...
});
`
You can also send an email with attachments
`js
var path = require('path');
pmk.email({
to: 'someaddress@somewhere.com',
from: 'fromaddress@somewhere.com',
subject: 'Test Email',
text: 'Hello World',
html: 'Hello World',
attachments: [
path.resolve(__dirname, 'cats.gif'),
path.resolve(__dirname, 'notes.txt')
]
}, function(err, response) {
// ...
});
// or
pmk.email({
to: 'someaddress@somewhere.com',
from: 'fromaddress@somewhere.com',
subject: 'Test Email',
text: 'Hello World',
html: 'Hello World',
attachments: [{
name: 'orders.csv',
content: ordersContent.toString('base64'),
contentType: 'text/csv'
}]
}, function(err, response) {
// ...
});
`
`js`
pmk.deliverystats(function(err, response) {});
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) {});
`
`js`
pmk.bounceTags(function(err, response) {});
`js`
pmk.bounce(bouncId, function(err, response) {});
`js`
pmk.bounceDump(bouncId, function(err, response) {});
Callback optional
`js`
pmk.bounceActivate(bounceId, function(err, response) {});
`js`
// simple example
pmk.outbound({
count: 10,
offset: 0
}, function(err, response) {});
`js`
// more specific
pmk.outbound({
count: 10,
offset: 0,
recipient: 'someone@somewhere.com',
fromemail: 'fromemail@somewhere.com',
tag: 'MyTag',
subject: 'Welcome Email'
}, function(err, response) {});
`js`
pmk.outboundMessage(messageId, function(err, response) {});
`js`
pmk.outboundMessageDump(messageId, function(err, response) {});
`js`
// simple example
pmk.inbound({
count: 10,
offset: 0
}, function(err, response) {});
`js`
// more specific
pmk.inbound({
count: 10,
offset: 0,
recipient: 'someone@somewhere.com',
fromemail: 'fromemail@somewhere.com',
tag: 'MyTag',
subject: 'Welcome Email',
mailboxhash: 'mailboxhashvalue'
}, function(err, response) {});
`js`
pmk.inboundMessage(messageId, function(err, response) {});
`js`
pmk.senders({
count: 10,
offset: 0
}, function(err, response) {});
`js`
pmk.sender(senderId, function(err, response) {});
The reply and callback are optional
`js`
pmk.createSender({
name: 'Sender Name',
from: 'senderemail@somewhere.com',
reply: 'replyto@somewhere.com'
}, function(err, response) {});
The reply and callback are optional
You cannot update the from address
`js`
pmk.updateSender(senderId, {
name: 'Sender Name',
reply: 'replyto@somewhere.com'
}, function(err, response) {});
The callback is optional
`js`
pmk.resendSender(senderId, function(err, response) {});
The callback is optional
`js`
pmk.deleteSender(senderId, function(err, response) {});
The callback is optional
`js`
pmk.verifySPF(senderId, function(err, response) {});
The callback is optional
`js`
pmk.requestDKIM(senderId, function(err, response) {});
`js`
pmk.servers({
count: 10,
offset: 0,
name: 'Production'
}, function(err, response) {});
`js`
pmk.server(serverId, function(err, response) {});
`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) {});
`
`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) {});
`
The callback is optional
`js``
pmk.deleteServer(serverId, function(err, response) {});