Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ var thru = require('through2'),
mail = require('mailgun-send');

exports.config = function (opts) { mail.config(opts); };
exports.send = function (obj) {
exports.send = function (obj) {
var stream = thru.obj(transform, flush);
if (obj) stream.write(obj);
return stream;
};
exports.sendWait = function (obj) {
var stream = thru.obj(transformWait, flush);
if (obj) stream.write(obj);
return stream;
};

function transform (obj, encoding, callback) {
if (typeof obj != 'object') return callback("Expecting object, but got " + typeof obj);
Expand All @@ -15,6 +20,18 @@ function transform (obj, encoding, callback) {
callback();
}

// Method will wait to pipe output until email is done being sent.
function transformWait (obj, encoding, callback) {
var me = this;
if (typeof obj != 'object') return callback("Expecting object, but got " + typeof obj);

// Pipe the output after email has been sent
mail.send(obj, function(err) {
me.push(obj);
callback();
});
}

function flush (callback) {
callback();
}