sendpost_javascript_sdk
v1.2.2
Published
Email API and SMTP relay to not just send and measure email sending, but also alert and optimise. We provide you with tools, expertise and support needed to reliably deliver emails to your customers inboxes on time, every time.
Downloads
4
Readme
sendpost_javascript_sdk
sendpost - JavaScript client for sendpost_javascript_sdk Email API and SMTP relay to not just send and measure email sending, but also alert and optimise. We provide you with tools, expertise and support needed to reliably deliver emails to your customers inboxes on time, every time.
Installation
For Node.js
npm
To publish the library as a npm, please follow the procedure in "Publishing npm packages".
Then install it via:
npm install sendpost_javascript_sdk --save
For browser
The library also works in the browser environment via npm and browserify. After following
the above steps with Node.js and installing browserify with npm install -g browserify
,
perform the following (assuming main.js is your entry file):
browserify main.js > bundle.js
Then include bundle.js in the HTML pages.
Webpack Configuration
Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:
module: {
rules: [
{
parser: {
amd: false
}
}
]
}
Getting Started
Please follow the installation instruction and execute the following JS code:
const { EmailApi, EmailMessage } = require('sendpost_javascript_sdk');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const message = new EmailMessage();
message.from = { email: '[email protected]' };
message.to = [{ email: '[email protected]' }]
message.subject = 'Hello'
message.htmlBody = '<strong>it works!</strong>';
message.ippool = 'PiedPiper'
const opts = {
emailMessage: message
};
try {
const data = await email.sendEmail(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
Example with cc, bcc and template:
const { EmailApi, EmailMessage } = require('sendpost_javascript_sdk');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const message = new EmailMessage();
message.from = { email: '[email protected]' };
message.to = [{
email: '[email protected]',
cc: [{ email: '[email protected]' }],
bcc: [{ email: '[email protected]' }],
}]
message.subject = 'Hello'
message.htmlBody = '<strong>it works!</strong>';
message.ippool = 'PiedPiper'
message.template = 'Welcome Mail'
const opts = {
emailMessage: message
};
try {
const data = await email.sendEmailWithTemplate(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
Suppressions
Create Suppressions
const { SuppressionApi, RSuppression } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const rSuppression = new RSuppression();
rSuppression.hardBounce = [{ email: 'richard@piedpiper_fake.com' }];
// fields are optional, but you have to send at least one of them.
// rSuppression.manual = [{ email: 'richard@piedpiper_fake2.com' }];
// rSuppression.spamComplaint = [{ email: 'richard@piedpiper_fake3.com' }];
// rSuppression.unsubscribe = [{ email: 'richard@piedpiper_fake4.com' }];
const opts = {
rSuppression: rSuppression
};
try {
const data = await suppressionApi.createSuppressions(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
Get Suppressions
const { SuppressionApi } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const opts = {
offset: 0,
limit: 10,
from: '2023-06-07',
to: '2023-08-02'
};
try {
const data = await suppressionApi.getSuppressions(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
Delete Suppressions
const { SuppressionApi, RDSuppression } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const rDSuppression = new RDSuppression();
rDSuppression.suppressions = [{ email: '[email protected]' }];
const opts = {
rDSuppression: rDSuppression
};
try {
const data = await suppressionApi.deleteSuppression(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
Count Suppressions
const { SuppressionApi } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key
(async function() {
const opts = {
from: '2023-06-07',
to: '2023-08-02'
};
try {
const data = await suppressionApi.count(apiKey, opts)
console.log('API called successfully. Returned data: ', data);
} catch (error) {
console.error(error);
}
})()
Documentation for API Endpoints
All URIs are relative to https://api.sendpost.io/api/v1
Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- sendpost.EmailApi | sendEmail | POST /subaccount/email/ | sendpost.EmailApi | sendEmailWithTemplate | POST /subaccount/email/template | sendpost.SuppressionApi | count | GET /subaccount/suppression/count | sendpost.SuppressionApi | createSuppressions | POST /subaccount/suppression/ | sendpost.SuppressionApi | deleteSuppression | DELETE /subaccount/suppression/ | sendpost.SuppressionApi | getSuppressions | GET /subaccount/suppression/ |
Documentation for Models
- sendpost.Attachment
- sendpost.City
- sendpost.CopyTo
- sendpost.CountStat
- sendpost.DeleteResponse
- sendpost.Device
- sendpost.EmailMessage
- sendpost.EmailResponse
- sendpost.EventMetadata
- sendpost.From
- sendpost.Os
- sendpost.QEmailMessage
- sendpost.QEvent
- sendpost.RDSuppression
- sendpost.RSuppression
- sendpost.ReplyTo
- sendpost.Suppression
- sendpost.SuppressionEmail
- sendpost.To
- sendpost.UserAgent
- sendpost.WebhookEvent
Documentation for Authorization
Endpoints do not require authorization.