From 1132952c42925f86624e0a7887f4bf3fc0c75db9 Mon Sep 17 00:00:00 2001 From: Michael-Rainabba Richardson Date: Sat, 26 Sep 2015 14:07:34 -0700 Subject: [PATCH 1/4] Minor update in README.md for changes to Hapi 8 regarding server.pack.plugins --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da4af03..15cdd90 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ server.pack.register pluginConf, (err) -> fnCallback = (err,result) -> # Do some stuff when done. -plugin = server.pack.plugins['hapi-mandrill'] +plugin = server.plugins['hapi-mandrill'] plugin.send("Angelina Jolie","angelina@jolie.com", {some: "payload"},"Hello Angelina","angelina-template", fnCallback) @@ -59,7 +59,7 @@ key is not found it will be passed verbatim. ## Exposed Properties ```Coffeescript -plugin = server.pack.plugins['hapi-mandrill'] +plugin = server.plugins['hapi-mandrill'] plugin.mandrillClient # Note this is null if you do not pass a key in options plugin.send(...) From 01779260e02234b9b0875c2ff67e62e61cfae148 Mon Sep 17 00:00:00 2001 From: Michael-Rainabba Richardson Date: Sat, 26 Sep 2015 14:08:15 -0700 Subject: [PATCH 2/4] Add sendNoTemplate method exposed to server Update README.md for sendNoTemplate --- README.md | 28 ++++++++++++++++++++++++++-- lib/index.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15cdd90..0a96fc6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ server.pack.register pluginConf, (err) -> ``` -## Send Mail +## Send Mail Using Template ```Coffeescript fnCallback = (err,result) -> @@ -46,7 +46,32 @@ fnCallback = (err,result) -> plugin = server.plugins['hapi-mandrill'] plugin.send("Angelina Jolie","angelina@jolie.com", {some: "payload"},"Hello Angelina","angelina-template", fnCallback) +``` +## Send Mail without Template +``` +fnCallback = (err,result) -> + # Do some stuff when done. + +var plugin = server.plugins['hapi-mandrill'], + message = { + from_email: "from@domain.tld", + from_name: "Person From", + to: [ + { + email: "to@domain.tld", + name: "Person To", + type: "to" + } + ], + subject: "Email Subject", + text: "Email Text", + html: "

Email HTML

" + }; + + +// See https://mandrillapp.com/api/docs/messages.JSON.html#method=send for full Message API definition +plugin.sendNoTemplate( message , fnCallback ) ``` ## Logging @@ -64,7 +89,6 @@ plugin = server.plugins['hapi-mandrill'] plugin.mandrillClient # Note this is null if you do not pass a key in options plugin.send(...) plugin.templateNameMapping = {...} - ``` ## See also diff --git a/lib/index.js b/lib/index.js index 443f77e..cff0b2f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -83,11 +83,18 @@ } ], track_opens: true, + track_clicks: true, auto_text: true, auto_html: true, inline_css: true } }; + + if ( options.tracking_domain ) { + sendTemplateOptions.tracking_domain = options.tracking_domain; + sendTemplateOptions.signing_domain = options.tracking_domain; + sendTemplateOptions.return_path_domain = options.tracking_domain; + } if (global_merge_vars) { sendTemplateOptions.message.global_merge_vars = global_merge_vars; } @@ -115,8 +122,38 @@ return success({}); } }; + + sendNoTemplate = function( message, cb2 ) { + var success, error; + + if (cb2 == null) { + cb2 = function() {}; + } + + success = function(result) { + if (options.verbose) { + server.log(['info', 'plugin', 'email-sent', 'hapi-mandrill', 'success'], "Successfully sent email", result); + } + return cb2(null, result); + }, + + error = function(err) { + if (options.verbose) { + server.log(['error', 'plugin', 'email-not-sent', 'hapi-mandrill', 'failure'], "Failed to send email for reason " + err, err); + } + return cb2(err); + }; + + if (mandrillClient) { + return mandrillClient.messages.send( { message: message, async: true }, success, error); // options.key + } else { + return success({}); + } + }; + server.expose('mandrillClient', mandrillClient); server.expose('send', send); + server.expose('sendNoTemplate', sendNoTemplate); server.expose('templateNameMapping', templateNameMapping); return cb(); }; From 05e31bf5c8f0550fca24803a6b41f96c8f43b505 Mon Sep 17 00:00:00 2001 From: Michael-Rainabba Richardson Date: Tue, 3 Nov 2015 17:44:10 -0700 Subject: [PATCH 3/4] node>=0.10.x --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c7f069..a789da4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "url": "https://github.com/codedoctor/hapi-mandrill.git" }, "engines": { - "node": "0.10.x" + "node": ">=0.10.x" }, "scripts": { "test": "node_modules/.bin/grunt testandcoverage" From 7c5edb81f0698a4d2ddcf361d89716cdb5216b17 Mon Sep 17 00:00:00 2001 From: Michael-Rainabba Richardson Date: Tue, 3 Nov 2015 17:52:38 -0700 Subject: [PATCH 4/4] release 2.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a789da4..814048b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hapi-mandrill", "description": "HAPI plugin that exposes mandrill api - used to send transactional emails.", - "version": "2.1.1", + "version": "2.1.2", "private": false, "main": "lib/index.js", "repository": {