blastengine SDK form Node.js
blastengine is developer friendly email distribution service.
blastengine
Usage
Install
npm i blastengine
Import
import { BlastEngine, Transaction, Bulk } from 'blastengine';
const { BlastEngine, Transaction, Bulk } = require('blastengine');
Initialize
new BlastEngine(config.userId, config.apiKey);
Transaction email
No attachment email
const transaction = new Transaction;
const res = await transaction
.setFrom(config.from.email, config.from.name)
.setSubject('Test subject')
.setTo(config.to)
.setText('Content of email')
.setHtml('<h1>Content of email')
.send();
console.log(res);
With attachment email
const transaction = new Transaction;
const res = await transaction
.setFrom(config.from.email, config.from.name)
.setSubject('Test subject')
.setTo(config.to)
.addAttachment('file.png')
.addAttachment('another.png')
.setText('Content of email')
.setHtml('<h1>Content of email')
.send();
console.log(res);
Bulk email
Create bulk email
const bulk = new Bluk;
bulk
.setFrom(config.from.email, config.from.name)
.setSubject('Test subject')
.setText('メールの本文 __code1__');
const res = await bulk.register();
console.log(res);
Update & add delivery address to bulk
bulk.setTo('test1@example.jp', {key: '__code1__', value: 'value!'});
bulk.setTo('test2@example.jp', {key: '__code1__', value: 'value2!'});
const updateRes = await bulk.update();
console.log(updateRes);
Upload delivery addresses by CSV file
const job = await bulk.import(path.resolve('./path/to/csv.csv'));
Waiting CSV uploaded
while (job.finished()) {
await job.get();
await new Promise((resolve) => setTimeout(resolve, 1000));
}
Download CSV import report
const zipBlob = await job.download();
await job.download(path.resolve('./tests/result.zip'));
Send bulk email
const sendRes = await bulk.send();
console.log(sendRes);
Delete bulk email
const deleteRes = await bulk.delete();
Usage
Get multiple usages
const usages = await Usage.get(3);
const usage = usages[0];
usage.month
usage.current
usage.remaining
usage.update_time
usage.plan_id
Get usage detail
const usages = await Usage.get(3);
const usage = usages[0];
await usage.get();
Get latest usage
const usage = await Usage.getLatest();
License
MIT.