Skip to content

Commit

Permalink
Merge branch 'feature/mail-service' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gocreating committed Oct 26, 2016
2 parents 4f58f62 + 5930351 commit 616ca6e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
14 changes: 14 additions & 0 deletions configs/project/gmail/credential.tmpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
development: {
username: 'your_gmail_username',
password: 'your_gmail_password',
},
test: {
username: 'your_gmail_username',
password: 'your_gmail_password',
},
production: {
username: 'your_gmail_username',
password: 'your_gmail_password',
},
};
12 changes: 12 additions & 0 deletions configs/project/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@ if (process.env.TRAVIS) {
linkedin: require('./passportStrategy/linkedin/credential'),
},
recaptcha: require('./recaptcha/credential'),
gmail: require('./gmail/credential'),
mailOptions: {
default: {
subject: 'Untitled Mail',
from: 'Express-React-Hmr-Boilerplate <no-reply@express-react-hmr-boilerplate.com>',
text: 'No Text',
html: '<pre>no html content<pre>',
},
development: {
to: 'gocreating@gmail.com',
},
},
};
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"mongoose": "^4.4.12",
"morgan": "^1.7.0",
"multer": "^1.1.0",
"nodemailer": "^2.6.4",
"object-assign": "^4.1.0",
"passport": "^0.3.2",
"passport-facebook": "^2.1.1",
Expand Down
1 change: 1 addition & 0 deletions src/common/constants/ErrorCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default {
ODM_VALIDATION: 'ODM_VALIDATION',
INVALID_RECAPTCHA: 'INVALID_RECAPTCHA',
SOCIAL_AUTH_FAIL: 'SOCIAL_AUTH_FAIL',
SEND_EMAIL_FAIL: 'SEND_EMAIL_FAIL',
};
6 changes: 6 additions & 0 deletions src/common/constants/Errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ export default {
title: 'Social Authentication Failed',
detail: 'Please make sure you authorize email to us.',
},
[ErrorCodes.SEND_EMAIL_FAIL]: {
code: ErrorCodes.SEND_EMAIL_FAIL,
status: 500,
title: 'Email Not Sent',
detail: 'Mail service didn\'t send the mail correctly.',
},
};
28 changes: 28 additions & 0 deletions src/server/api/nodemailer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import assign from 'object-assign';
import nodemailer from 'nodemailer';
import configs from '../../../configs/project/server';

let defaultTransport = (
`smtps://${configs.gmail[process.env.NODE_ENV].username}%40gmail.com:` +
`${configs.gmail[process.env.NODE_ENV].password}@smtp.gmail.com`
);

export default (transport = defaultTransport) => {
let transporter = nodemailer.createTransport(transport);
return {
sendMail: (mailOptions) => new Promise((resolve, reject) => {
mailOptions = assign(
{},
configs.mailOptions.default,
configs.mailOptions[process.env.NODE_ENV],
mailOptions
);
transporter.sendMail(mailOptions, (err, info) => {
if (err) {
return reject(err);
}
return resolve(info);
});
}),
};
};

0 comments on commit 616ca6e

Please sign in to comment.