-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
46 lines (44 loc) · 1.39 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var _ = require('underscore');
var nodemailer = require('nodemailer');
var path = require('path');
var through2 = require('through2');
var util = require('util');
var gutil = require('gulp-util');
module.exports = function (options) {
options = _.defaults(options || {}, {
to: [],
from: 'nodemailer <[email protected]>',
subject: null,
html: null,
text: null
});
var transporter = nodemailer.createTransport(
options.transporter || { service: 'sendmail' }
);
return through2.obj(function (file, enc, next) {
if (file.isNull()) {
this.push(file);
return next();
}
var to = options.to.join(',');
var subject = options.subject || _subjectFromFilename(file.path);
return transporter.sendMail({
from: options.from,
to: to,
subject: subject,
html: file.contents.toString()
}, function (error, info) {
if (error) {
console.error(error);
return next();
}
gutil.log('Send email', gutil.colors.cyan(subject), 'to',
gutil.colors.red(to));
next();
});
});
};
_subjectFromFilename = function (filename) {
var name = path.basename(filename).replace(path.extname(filename), '');
return util.format('[TEST] %s', name);
};