
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
mailshake-node
Advanced tools
This is the official Node.js library for the Mailshake API. View the docs here.
npm install mailshake-node
Requiring the mailshake-node
module takes your API key as an argument. Every
operation returns a Promise. Errors from the calling API will populate the
code
property of the error contained by the operation's Promise.
const mailshake = require('mailshake-node')('my-api-key');
return mailshake.campaigns
.list({
search: 'Venkman',
})
.then((result) => {
console.log(JSON.stringify(result, null, 2));
})
.catch((err) => {
console.error(`${err.code}: ${err.message}`);
});
Don't forget to change
my-api-key
to your own key.
mailshake-node
has hooks to support most any OAuth library. You can either
customize the request with customizeRequest
or outright replace how the
request is made with overrideCreateRequest
:
const mailshake = require('mailshake-node')({
customizeRequest(options) => {
// options.headers.authorization = [...oauth header...]
return options;
}),
// or
overrideCreateRequest(options, callbackFn) => {
return https(options, callbackFn);
}),
});
See our official API docs for details.
When a request accepts paging parameters, a call to get the next page is conveniently attached to your result:
mailshake.campaigns.list()
.then((result) => {
console.log(`Page 1: ${JSON.stringify(result, null, 2)}`);
// Just call `next` to get the next page of data
return result.next();
})
.then((result) => {
console.log(`Page 2: ${JSON.stringify(result, null, 2)}`);
});
The Mailshake API lets you subscribe to real-time pushes so you can react in
your app. To do this you tell Mailshake where to make HTTPS requests, your web
server handles them, and sends back a 200
status. See our docs on
this for more details.
express
as your web serverconst express = require('express');
const bodyParser = require('body-parser');
const mailshake = require('mailshake-node')('my-api-key');
const PushHandler = require('mailshake-node').PushHandler;
// Initialize your express app, making sure to include bodyParser
const app = express();
app.use(bodyParser.json({}));
// Set up how your site is being hosted
const handler = new PushHandler(mailshake, {
baseUrl: 'https://mailshake-test.ngrok.io',
rootPath: 'pushes',
secret: 'my-secret'
});
// Listen when pushes are received and take action
handler.on('push', push => {
console.log(JSON.stringify(push, null, 2));
});
// Listen when there was some kind of error handling a push
handler.on('pushError', err => {
console.error(`${err.code}: ${err.stack}`);
});
// Hook it up
handler.hookExpress(app);
// Start your server
const port = 80;
app.listen(port);
console.log(`Listening on http://127.0.0.1:${port}`);
Don't forget to change
my-api-key
to your own key.
Tell Mailshake what you want to listen for. This option will automatically
format your subscription so that PushHandler
can handle it:
handler
.subscribe('Clicked', {
// Filter options
})
.then((targetUrl) => {
// Store targetUrl somewhere so you can unsubscribe later
})
.catch((err) => {
console.error(`${err.code}: ${err.stack}`);
});
When you're done, unsubscribe
to stop receiving pushes:
handler
.unsubscribe(targetUrl)
.catch((err) => {
console.error(`${err.code}: ${err.stack}`);
});
Mailshake will send your server a request like this:
{
"resource_url": "https://api.mailshake.com/2017-04-01/..."
}
Use the resolvePush
operation to fetch the full data behind the push:
const resolvePush = require('mailshake-node').resolvePush;
resolvePush(mailshake, {
// The object Mailshake sent your server
})
.then((result) => {
console.log(JSON.stringify(result, null, 2));
})
.catch((err) => {
console.error(`${err.code}: ${err.message}`);
});
express
In case you can't or don't want to use our more complete PushHandler
solution,
a pushHandlerExpress
function is exposed on this module that encapsulates
fetching the push's details and communicating back to Mailshake about the
receipt being successful or not:
const pushHandlerExpress = require('mailshake-node').pushHandlerExpress;
// NOTE: Put this code inside the handler for your endpoint:
pushHandlerExpress(mailshake, receivedPush, response)
.then((result) => {
console.log(JSON.stringify(result, null, 2));
})
.catch((err) => {
console.error(`${err.code}: ${err.message}`);
});
If you're not using our main handler, you can subscribe to pushes like this:
return mailshake.push
.create({
targetUrl: '[a unique url for this push to store for later so you can unsubscribe]',
event: 'Clicked',
filter: {
// Filter options
},
})
.then((result) => {
// Nothing really to do here
})
.catch((err) => {
console.error(`${err.code}: ${err.message}`);
});
Unsubscribe your subscriptions like this:
return mailshake.push
.delete({
targetUrl: '[your unique url for the push to unsubscribe]',
})
.then((result) => {
// Nothing really to do here
})
.catch((err) => {
console.error(`${err.code}: ${err.message}`);
});
If you have improvements, please create a pull request for our consideration.
Our test suites for this module aren't yet part of the source. At the moment
only one test is wired up here as a sanity check and to test connectivity. To
use it create a local CONFIG.json
file in the root directory of this repo like
this:
{
"apiKey": "my-api-key"
}
Update it with your API key and then run npm test
.
FAQs
Node.js Library for the Mailshake API
We found that mailshake-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.