From 4dfb0c2fa8e86e0bc37624a53d85893a71f42ad1 Mon Sep 17 00:00:00 2001 From: James Thomas Date: Mon, 14 Aug 2017 20:20:12 -0400 Subject: [PATCH 1/4] Updating Node and NPM requirements in package + travis to work with Dockerfile node versions (6.x has incremented) --- .travis.yml | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b23567b..e092c961 100755 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: node_js dist: trusty sudo: false node_js: - - "6.11.1" + - "6.11.2" env: - NODE_ENV=travis TRAVIS=travis CXX=g++-4.8 services: diff --git a/package.json b/package.json index 87df0490..7cf94927 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "url": "https://github.com/whitef0x0/tellform.git" }, "engines": { - "node": "6.11.1", - "npm": "3.3.6" + "node": "6.11.2", + "npm": "3.10.10" }, "scripts": { "addcontrib": "all-contributors add", From 8ae13ea6c34c04d2a1b52bca14ee41f4465042cb Mon Sep 17 00:00:00 2001 From: James Thomas Date: Mon, 14 Aug 2017 20:57:30 -0400 Subject: [PATCH 2/4] Updating Nodemailer to 4.0 to support verification methods --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7cf94927..6e324668 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "mongoose-utilities": "~0.1.1", "morgan": "~1.8.1", "multer": "^1.3.0", - "nodemailer": "~1.10.0", + "nodemailer": "~4.0.0", "nodemailer-sendgrid-transport": "^0.2.0", "nodemailer-sparkpost-transport": "^1.0.0", "passport": "~0.3.0", From f80c0e9bcc08be5f9b8159eab050121a9c0ae6a1 Mon Sep 17 00:00:00 2001 From: James Thomas Date: Mon, 14 Aug 2017 20:58:26 -0400 Subject: [PATCH 3/4] Added custom mail host via MAILER_SERVICE_PROVIDER, MAILER_SMTP_PORT, and MAILER_SMTP_SECURE env vars --- .../users.authentication.server.controller.js | 5 ++--- app/models/user.server.model.js | 8 ++++++++ config/env/development.js | 10 +++++++++- config/env/production.js | 14 +++++++++++--- config/env/secure.js | 10 +++++++++- config/env/test.js | 10 +++++++++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/controllers/users/users.authentication.server.controller.js b/app/controllers/users/users.authentication.server.controller.js index 7eba442a..4ad8154d 100755 --- a/app/controllers/users/users.authentication.server.controller.js +++ b/app/controllers/users/users.authentication.server.controller.js @@ -95,7 +95,6 @@ exports.resendVerificationEmail = function(req, res, next){ * Signup */ exports.signup = function(req, res) { - // For security measures we remove the roles from the req.body object delete req.body.roles; @@ -106,13 +105,13 @@ exports.signup = function(req, res) { user.provider = 'local'; // Then save the temporary user nev.createTempUser(user, function (err, existingPersistentUser, newTempUser) { - debugger; - if (err) { + if (err) { return res.status(400).send({ message: errorHandler.getErrorMessage(err) }); } + // new user created if (newTempUser) { var URL = newTempUser[nev.options.URLFieldName]; diff --git a/app/models/user.server.model.js b/app/models/user.server.model.js index 17cac977..a22f53d4 100755 --- a/app/models/user.server.model.js +++ b/app/models/user.server.model.js @@ -15,6 +15,14 @@ var mongoose = require('mongoose'), var smtpTransport = nodemailer.createTransport(config.mailer.options); +// verify connection configuration on startup +smtpTransport.verify(function(error, success) { + if (error) { + console.log('Your mail configuration is incorrect', error); + } else { + console.log('Mail server is ready to take our messages'); + } +}); /** * A Validation function for local strategy properties diff --git a/config/env/development.js b/config/env/development.js index 2506743b..7771b6e0 100755 --- a/config/env/development.js +++ b/config/env/development.js @@ -43,7 +43,15 @@ module.exports = { }, mailer: { from: process.env.MAILER_FROM || 'no-reply@tellform.com', - options: { + options: process.env.MAILER_SMTP_HOST ? { //Uses custom SMTP if MAILER_SMTP_HOST is set + host: process.env.MAILER_SMTP_HOST || '', + port: process.env.MAILER_SMTP_PORT || 465, + secure: process.env.MAILER_SMTP_SECURE || true, + auth: { + user: process.env.MAILER_EMAIL_ID || '', + pass: process.env.MAILER_PASSWORD || '' + } + } : { service: process.env.MAILER_SERVICE_PROVIDER || '', auth: { user: process.env.MAILER_EMAIL_ID || '', diff --git a/config/env/production.js b/config/env/production.js index e0d00fc3..110fd1f4 100755 --- a/config/env/production.js +++ b/config/env/production.js @@ -59,11 +59,19 @@ module.exports = { }, mailer: { from: process.env.MAILER_FROM || 'testing@'+process.env.SPARKPOST_SANDBOX_DOMAIN || 'no-reply@tellform.com', - options: { + options: process.env.MAILER_SMTP_HOST ? { //Uses custom SMTP if MAILER_SMTP_HOST is set + host: process.env.MAILER_SMTP_HOST || '', + port: process.env.MAILER_SMTP_PORT || 465, + secure: process.env.MAILER_SMTP_SECURE || true, + auth: { + user: process.env.MAILER_EMAIL_ID || '', + pass: process.env.MAILER_PASSWORD || '' + } + } : { service: process.env.MAILER_SERVICE_PROVIDER || '', auth: { - user: process.env.MAILER_EMAIL_ID || process.env.SPARKPOST_SMTP_USERNAME || '', - pass: process.env.MAILER_PASSWORD || process.env.SPARKPOST_SMTP_PASSWORD || '' + user: process.env.MAILER_EMAIL_ID || '', + pass: process.env.MAILER_PASSWORD || '' } } } diff --git a/config/env/secure.js b/config/env/secure.js index 5f4c9b8e..4c6a584f 100755 --- a/config/env/secure.js +++ b/config/env/secure.js @@ -66,7 +66,15 @@ module.exports = { }, mailer: { from: process.env.MAILER_FROM || '', - options: { + options: process.env.MAILER_SMTP_HOST ? { //Uses custom SMTP if MAILER_SMTP_HOST is set + host: process.env.MAILER_SMTP_HOST || '', + port: process.env.MAILER_SMTP_PORT || 587, + secure: process.env.MAILER_SMTP_SECURE || true, + auth: { + user: process.env.MAILER_EMAIL_ID || '', + pass: process.env.MAILER_PASSWORD || '' + } + } : { service: process.env.MAILER_SERVICE_PROVIDER || '', auth: { user: process.env.MAILER_EMAIL_ID || '', diff --git a/config/env/test.js b/config/env/test.js index b6d24812..29e4e821 100755 --- a/config/env/test.js +++ b/config/env/test.js @@ -52,7 +52,15 @@ module.exports = { }, mailer: { from: process.env.MAILER_FROM || 'MAILER_FROM', - options: { + options: process.env.MAILER_SMTP_HOST ? { //Uses custom SMTP if MAILER_SMTP_HOST is set + host: process.env.MAILER_SMTP_HOST || '', + port: process.env.MAILER_SMTP_PORT || 587, + secure: process.env.MAILER_SMTP_SECURE || true, + auth: { + user: process.env.MAILER_EMAIL_ID || '', + pass: process.env.MAILER_PASSWORD || '' + } + } : { service: process.env.MAILER_SERVICE_PROVIDER || '', auth: { user: process.env.MAILER_EMAIL_ID || '', From c1f08fec144c64e5dbe75768263996acad0d202d Mon Sep 17 00:00:00 2001 From: James Thomas Date: Mon, 14 Aug 2017 21:23:06 -0400 Subject: [PATCH 4/4] Updating docs for custom smtp updates --- README.md | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index df51617a..513d105d 100755 --- a/README.md +++ b/README.md @@ -83,12 +83,23 @@ OR create your .env file GOOGLE_ANALYTICS_ID=yourGAID PRERENDER_TOKEN=yourPrerender.ioToken COVERALLS_REPO_TOKEN=yourCoveralls.ioToken -MAILER_EMAIL_ID=SMTP_Injection -MAILER_FROM=noreply@yourdomain.com -MAILER_PASSWORD=your_sendgrid_apikey -MAILER_SERVICE_PROVIDER=SendGrid BASE_URL=localhost DSN_KEY=yourPrivateRavenKey + +# Mail config +MAILER_EMAIL_ID=user@domain.com +MAILER_PASSWORD=some-pass +MAILER_FROM=user@domain.com + +# Use this for one of Nodemailer's pre-configured service providers +MAILER_SERVICE_PROVIDER=SendGrid + +# Use these for a custom service provider +# Note: MAILER_SMTP_HOST will override MAILER_SERVICE_PROVIDER +MAILER_SMTP_HOST=smtp.domain.com +MAILER_SMTP_PORT=465 +MAILER_SMTP_SECURE=true + ``` Side note: ___Currently we are using Raven and Sentry [https://www.getsentry.com](https://www.getsentry.com) for error logging. To use it you must provide a valid private DSN key in your .env file and a public DSN key in app/views/layout.index.html___ @@ -174,7 +185,7 @@ $ bower install ``` #### Prepare .env file: -Create .env file at project root folder. Fill in MAILER_SERVICE_PROVIDER, MAILER_EMAIL_ID and MAILER_PASSWORD. +Create .env file at project root folder. Fill in MAILER_EMAIL_ID and MAILER_PASSWORD, and either MAILER_SERVICE_PROVIDER using a [Nodemailer Well-known service](https://nodemailer.com/smtp/well-known/) or MAILER_SMTP_HOST, MAILER_SMTP_PORT, and MAILER_SMTP_SECURE for a custom SMTP server. ``` APP_NAME=forma APP_DESC= @@ -183,10 +194,6 @@ NODE_ENV=development BASE_URL=localhost:5000 PORT=5000 username=forma_admin -MAILER_SERVICE_PROVIDER= -MAILER_EMAIL_ID= -MAILER_PASSWORD= -MAILER_FROM=forma@data.gov.sg SIGNUP_DISABLED=false SUBDOMAINS_DISABLED=true DISABLE_CLUSTER_MODE=true @@ -194,6 +201,20 @@ GOOGLE_ANALYTICS_ID= RAVEN_DSN= PRERENDER_TOKEN= COVERALLS_REPO_TOKEN= + +# Mail config +MAILER_EMAIL_ID=forma@data.gov.sg +MAILER_PASSWORD=some-pass +MAILER_FROM=forma@data.gov.sg + +# Use this for one of Nodemailer's pre-configured service providers +MAILER_SERVICE_PROVIDER= + +# Use these for a custom service provider +# Note: MAILER_SMTP_HOST will override MAILER_SERVICE_PROVIDER +MAILER_SMTP_HOST= +MAILER_SMTP_PORT=465 +MAILER_SMTP_SECURE=true ``` #### Deploy with Docker: