From efe37cfcf53d91a5bda38ca3344e736eface4d00 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Wed, 25 May 2016 15:40:17 -0400 Subject: [PATCH 1/8] Email templates * Email templates for email verification and password reset request * Use the same variable as Parse.com * Update README to explain how to use the new feature --- README.md | 40 ++++++++++++++++++++++++++++++++++++ index.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/README.md b/README.md index 7e32c3b..8a005c9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # parse-server-simple-mailgun-adapter Used to send Parse Server password reset and email verification emails though Mailgun + + +## How to use +``` +var server = ParseServer({ + ... + emailAdapter: { + module: 'parse-server-simple-mailgun-adapter', + options: { + // The address that your emails come from + fromAddress: 'no-reply@yourdomain.com', + // Your domain from mailgun.com + domain: 'mg.yourdomain.com', + // Your API key from mailgun.com + apiKey: 'key-0123456789abcdefghijklmnopqrstuv', + // Verification email subject + verificationSubject: 'Please verify your e-mail for %appname%', + // Verification email body + verificationBody: 'Hi,\n\nYou are being asked to confirm the e-mail address %email% with %appname%\n\nClick here to confirm it:\n%link%', + // Password reset email subject + passwordResetSubject: 'Password Reset Request for %appname%', + // Password reset email body + passwordResetBody: 'Hi,\n\nYou requested a password reset for %appname%.\n\nClick here to reset it:\n%link%' + } + } + ... +}); +``` + +## Variables + +Customize the e-mail sent to your users when they reset their password or when we verify their email address. The following variables will be automatically filled in with their appropriate values: + +`%username%` the user's display name + +`%email%` the user's email address + +`%appname%` your application's display name + +`%link%` the link the user must click to perform the requested action \ No newline at end of file diff --git a/index.js b/index.js index 690b7dc..2d454fb 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,67 @@ var SimpleMailgunAdapter = mailgunOptions => { if (!mailgunOptions || !mailgunOptions.apiKey || !mailgunOptions.domain || !mailgunOptions.fromAddress) { throw 'SimpleMailgunAdapter requires an API Key, domain, and fromAddress.'; } + + mailgunOptions.verificationSubject = + mailgunOptions.verificationSubject || + 'Please verify your e-mail for %appname%'; + mailgunOptions.verificationBody = + mailgunOptions.verificationBody || + 'Hi,\n\nYou are being asked to confirm the e-mail address %email% ' + + 'with %appname%\n\nClick here to confirm it:\n%link%'; + mailgunOptions.passwordResetSubject = + mailgunOptions.passwordResetSubject || + 'Password Reset Request for %appname%'; + mailgunOptions.passwordResetBody = + mailgunOptions.passwordResetBody || + 'Hi,\n\nYou requested a password reset for %appname%.\n\nClick here ' + + 'to reset it:\n%link%'; + + var mailgun = Mailgun(mailgunOptions); + function fillVariables(text) { + text = text.replace("%username%", options.user.get("username")); + text = text.replace("%email%", options.user.get("email")); + text = text.replace("%appname%", options.appName); + text = text.replace("%link%", options.link); + return text; + } + + var sendVerificationEmail = options => { + var message = { + from: mailgunOptions.fromAddress, + to: options.user.get("email"), + subject: mailgunOptions.verificationSubject, + text: fillVariables(mailgunOptions.verificationBody) + } + return new Promise((resolve, reject) => { + mailgun.messages().send(data, (err, body) => { + if (typeof err !== 'undefined') { + reject(err); + } + resolve(body); + }); + }); + } + + var sendPasswordResetEmail = options => { + var message = { + from: mailgunOptions.fromAddress, + to: options.user.get("email"), + subject: mailgunOptions.passwordResetSubject, + text: fillVariables(mailgunOptions.passwordResetBody) + } + return new Promise((resolve, reject) => { + mailgun.messages().send(data, (err, body) => { + if (typeof err !== 'undefined') { + reject(err); + } + resolve(body); + }); + }); + } + var sendMail = mail => { var data = { from: mailgunOptions.fromAddress, @@ -26,6 +85,8 @@ var SimpleMailgunAdapter = mailgunOptions => { } return Object.freeze({ + sendVerificationEmail: sendVerificationEmail, + sendPasswordResetEmail: sendPasswordResetEmail, sendMail: sendMail }); } From cea907aa471921da02f32ca4c2f109ca19df4fc7 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Wed, 25 May 2016 15:43:55 -0400 Subject: [PATCH 2/8] Add a new contributor --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7c44b1c..9dec046 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "parse-server-simple-mailgun-adapter", - "version": "1.0.0", + "version": "1.0.1", "description": "Used to send Parse Server password reset and email verification emails though Mailgun", "main": "index.js", "scripts": { @@ -20,6 +20,11 @@ "bugs": { "url": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter/issues" }, + "contributors": [ + { "name" : "Benjamin Comeau" + , "email" : "benjamin@bcomeau.ca" + } + ], "homepage": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter#readme", "dependencies": { "mailgun-js": "^0.7.7" From ffad6174c70b725129e551cfc73e24300b22edd7 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Wed, 25 May 2016 15:53:18 -0400 Subject: [PATCH 3/8] Change package.json to be a scoped package --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9dec046..e8ccca4 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "parse-server-simple-mailgun-adapter", + "name": "@bcomeau/parse-server-simple-mailgun-adapter", "version": "1.0.1", "description": "Used to send Parse Server password reset and email verification emails though Mailgun", "main": "index.js", @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter.git" + "url": "git+https://github.com/bcomeau/parse-server-simple-mailgun-adapter.git" }, "keywords": [ "parse", @@ -18,14 +18,14 @@ "author": "Drew Gross", "license": "BSD-3-Clause", "bugs": { - "url": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter/issues" + "url": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter/issues" }, "contributors": [ { "name" : "Benjamin Comeau" , "email" : "benjamin@bcomeau.ca" } ], - "homepage": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter#readme", + "homepage": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter#readme", "dependencies": { "mailgun-js": "^0.7.7" } From fadf5e623703db931fb57383072596e7deb500fc Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Wed, 25 May 2016 15:54:59 -0400 Subject: [PATCH 4/8] Fix contributors format --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index e8ccca4..04d2069 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,7 @@ "url": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter/issues" }, "contributors": [ - { "name" : "Benjamin Comeau" - , "email" : "benjamin@bcomeau.ca" - } + "Benjamin Comeau " ], "homepage": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter#readme", "dependencies": { From 1c11f9e0fd9c80dff42ce1bdf19b9225fc962799 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Wed, 25 May 2016 16:18:20 -0400 Subject: [PATCH 5/8] fix pass options to fillVariables function --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2d454fb..6c3757b 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ var SimpleMailgunAdapter = mailgunOptions => { var mailgun = Mailgun(mailgunOptions); - function fillVariables(text) { + function fillVariables(text, options) { text = text.replace("%username%", options.user.get("username")); text = text.replace("%email%", options.user.get("email")); text = text.replace("%appname%", options.appName); @@ -37,7 +37,7 @@ var SimpleMailgunAdapter = mailgunOptions => { from: mailgunOptions.fromAddress, to: options.user.get("email"), subject: mailgunOptions.verificationSubject, - text: fillVariables(mailgunOptions.verificationBody) + text: fillVariables(mailgunOptions.verificationBody, options) } return new Promise((resolve, reject) => { mailgun.messages().send(data, (err, body) => { @@ -54,7 +54,7 @@ var SimpleMailgunAdapter = mailgunOptions => { from: mailgunOptions.fromAddress, to: options.user.get("email"), subject: mailgunOptions.passwordResetSubject, - text: fillVariables(mailgunOptions.passwordResetBody) + text: fillVariables(mailgunOptions.passwordResetBody, options) } return new Promise((resolve, reject) => { mailgun.messages().send(data, (err, body) => { From b77f079f61580120682b8e1a0a26af85dc0c395f Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Thu, 26 May 2016 11:49:14 -0400 Subject: [PATCH 6/8] replace variables in subjects --- index.js | 11 +++++------ package.json | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 6c3757b..49137f4 100644 --- a/index.js +++ b/index.js @@ -33,10 +33,10 @@ var SimpleMailgunAdapter = mailgunOptions => { } var sendVerificationEmail = options => { - var message = { + var data = { from: mailgunOptions.fromAddress, to: options.user.get("email"), - subject: mailgunOptions.verificationSubject, + subject: fillVariables(mailgunOptions.verificationSubject, options), text: fillVariables(mailgunOptions.verificationBody, options) } return new Promise((resolve, reject) => { @@ -50,10 +50,10 @@ var SimpleMailgunAdapter = mailgunOptions => { } var sendPasswordResetEmail = options => { - var message = { + var data = { from: mailgunOptions.fromAddress, to: options.user.get("email"), - subject: mailgunOptions.passwordResetSubject, + subject: fillVariables(mailgunOptions.passwordResetSubject, options), text: fillVariables(mailgunOptions.passwordResetBody, options) } return new Promise((resolve, reject) => { @@ -71,9 +71,8 @@ var SimpleMailgunAdapter = mailgunOptions => { from: mailgunOptions.fromAddress, to: mail.to, subject: mail.subject, - text: mail.text, + text: mail.text } - return new Promise((resolve, reject) => { mailgun.messages().send(data, (err, body) => { if (typeof err !== 'undefined') { diff --git a/package.json b/package.json index 04d2069..459ea09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bcomeau/parse-server-simple-mailgun-adapter", - "version": "1.0.1", + "version": "1.0.4", "description": "Used to send Parse Server password reset and email verification emails though Mailgun", "main": "index.js", "scripts": { From 3fd8f9b54159a08cf18e6e22a03ae4dc7d883a46 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Thu, 26 May 2016 12:01:33 -0400 Subject: [PATCH 7/8] revert to previous package.json --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 459ea09..baf5e5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@bcomeau/parse-server-simple-mailgun-adapter", - "version": "1.0.4", + "name": "parse-server-simple-mailgun-adapter", + "version": "1.0.1", "description": "Used to send Parse Server password reset and email verification emails though Mailgun", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/bcomeau/parse-server-simple-mailgun-adapter.git" + "url": "git+https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter.git" }, "keywords": [ "parse", @@ -18,12 +18,12 @@ "author": "Drew Gross", "license": "BSD-3-Clause", "bugs": { - "url": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter/issues" + "url": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter/issues" }, "contributors": [ "Benjamin Comeau " - ], - "homepage": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter#readme", + ], + "homepage": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter#readme", "dependencies": { "mailgun-js": "^0.7.7" } From 27a8e4b140be19feb25f3006de77785736162400 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Fri, 22 Jul 2016 14:47:02 -0400 Subject: [PATCH 8/8] Publish on NPM parse-server-mailgun-adapter-template --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index baf5e5a..2eafc9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "parse-server-simple-mailgun-adapter", - "version": "1.0.1", + "name": "parse-server-mailgun-adapter-template", + "version": "1.1.1", "description": "Used to send Parse Server password reset and email verification emails though Mailgun", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter.git" + "url": "git+https://github.com/bcomeau/parse-server-simple-mailgun-adapter.git" }, "keywords": [ "parse", @@ -18,12 +18,12 @@ "author": "Drew Gross", "license": "BSD-3-Clause", "bugs": { - "url": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter/issues" + "url": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter/issues" }, "contributors": [ "Benjamin Comeau " ], - "homepage": "https://github.com/ParsePlatform/parse-server-simple-mailgun-adapter#readme", + "homepage": "https://github.com/bcomeau/parse-server-simple-mailgun-adapter#readme", "dependencies": { "mailgun-js": "^0.7.7" }