Merge pull request #221 from James9074/custom-email
Adding Custom SMTP Server Config
This commit is contained in:
commit
b84ff46a31
|
@ -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:
|
||||
|
|
39
README.md
39
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
|
||||
```
|
||||
|
||||
**Note**: You can view the compatible types for MAILER_SERVICE_PROVIDER [here](https://nodemailer.com/smtp/well-known/)
|
||||
|
|
|
@ -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) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// new user created
|
||||
if (newTempUser) {
|
||||
var URL = newTempUser[nev.options.URLFieldName];
|
||||
|
|
|
@ -13,6 +13,17 @@ var mongoose = require('mongoose'),
|
|||
querystring = require('querystring'),
|
||||
nodemailer = require('nodemailer');
|
||||
|
||||
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
|
||||
*/
|
||||
|
|
10
config/env/development.js
vendored
10
config/env/development.js
vendored
|
@ -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 || '',
|
||||
|
|
14
config/env/production.js
vendored
14
config/env/production.js
vendored
|
@ -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 || ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
config/env/secure.js
vendored
10
config/env/secure.js
vendored
|
@ -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 || '',
|
||||
|
|
10
config/env/test.js
vendored
10
config/env/test.js
vendored
|
@ -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 || '',
|
||||
|
|
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue