1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var mailer = require('mailgun-send'),
|
13 | _ = require('lodash');
|
14 |
|
15 |
|
16 | module.exports = function (grunt) {
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | grunt.registerMultiTask('mailgun', 'Send emails through mailgun as part of your build.', function () {
|
22 | var done = this.async();
|
23 | var opts = _.pick(this.data.options,['sender','recipient','subject','body']);
|
24 |
|
25 |
|
26 | mailer.config({key: this.data.options.key});
|
27 |
|
28 | if (this.files.length > 0) {
|
29 | var i = this.files.length;
|
30 | this.filesSrc.forEach(function (filePath) {
|
31 | var _opts = _.clone(opts);
|
32 | _opts.body = grunt.file.read(filePath);
|
33 | mailer.send(_opts, function () {
|
34 | grunt.log.writeln('Sent' + filePath + ' to ' + _opts.recipient);
|
35 | if (i < 1) { done(); } else { i--; }
|
36 | });
|
37 |
|
38 | });
|
39 |
|
40 | } else {
|
41 | mailer.send(opts, function () {
|
42 | grunt.log.writeln('Sent mailgun msg to ' + opts.recipient);
|
43 | done();
|
44 | });
|
45 | }
|
46 |
|
47 | });
|
48 |
|
49 | };
|