Nightly Punk Masters

    blastengine
    TypeScript icon, indicating that this package has built-in type declarations

    1.5.0 • Public • Published

    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';
    // or
    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);
    // { delivery_id: 22 }

    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);
    // { delivery_id: 22 }

    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);
    // { delivery_id: 22 }

    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);
    // { delivery_id: 22 }

    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();
    // or
    await job.download(path.resolve('./tests/result.zip'));

    Send bulk email

    const sendRes = await bulk.send();
    console.log(sendRes);
    // { delivery_id: 22 }

    Delete bulk email

    const deleteRes = await bulk.delete();
    // { delivery_id: 22 }

    Usage

    Get multiple usages

    const usages = await Usage.get(3);
    const usage = usages[0];
    usage.month // -> 202208
    usage.current // ->  44
    usage.remaining // ->  9956
    usage.update_time // ->  undefined
    usage.plan_id // ->  'be-plan-10000

    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.

    Keywords

    none

    Install

    npm i blastengine

    DownloadsWeekly Downloads

    23

    Version

    1.5.0

    License

    MIT

    Unpacked Size

    78.5 kB

    Total Files

    40

    Last publish

    Collaborators

    • moongift