Skip to content

Commit 616ca6e

Browse files
committed
Merge branch 'feature/mail-service' into dev
2 parents 4f58f62 + 5930351 commit 616ca6e

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
development: {
3+
username: 'your_gmail_username',
4+
password: 'your_gmail_password',
5+
},
6+
test: {
7+
username: 'your_gmail_username',
8+
password: 'your_gmail_password',
9+
},
10+
production: {
11+
username: 'your_gmail_username',
12+
password: 'your_gmail_password',
13+
},
14+
};

configs/project/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,17 @@ if (process.env.TRAVIS) {
1919
linkedin: require('./passportStrategy/linkedin/credential'),
2020
},
2121
recaptcha: require('./recaptcha/credential'),
22+
gmail: require('./gmail/credential'),
23+
mailOptions: {
24+
default: {
25+
subject: 'Untitled Mail',
26+
from: 'Express-React-Hmr-Boilerplate <no-reply@express-react-hmr-boilerplate.com>',
27+
text: 'No Text',
28+
html: '<pre>no html content<pre>',
29+
},
30+
development: {
31+
to: 'gocreating@gmail.com',
32+
},
33+
},
2234
};
2335
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"mongoose": "^4.4.12",
106106
"morgan": "^1.7.0",
107107
"multer": "^1.1.0",
108+
"nodemailer": "^2.6.4",
108109
"object-assign": "^4.1.0",
109110
"passport": "^0.3.2",
110111
"passport-facebook": "^2.1.1",

src/common/constants/ErrorCodes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export default {
1010
ODM_VALIDATION: 'ODM_VALIDATION',
1111
INVALID_RECAPTCHA: 'INVALID_RECAPTCHA',
1212
SOCIAL_AUTH_FAIL: 'SOCIAL_AUTH_FAIL',
13+
SEND_EMAIL_FAIL: 'SEND_EMAIL_FAIL',
1314
};

src/common/constants/Errors.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,10 @@ export default {
6767
title: 'Social Authentication Failed',
6868
detail: 'Please make sure you authorize email to us.',
6969
},
70+
[ErrorCodes.SEND_EMAIL_FAIL]: {
71+
code: ErrorCodes.SEND_EMAIL_FAIL,
72+
status: 500,
73+
title: 'Email Not Sent',
74+
detail: 'Mail service didn\'t send the mail correctly.',
75+
},
7076
};

src/server/api/nodemailer.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import assign from 'object-assign';
2+
import nodemailer from 'nodemailer';
3+
import configs from '../../../configs/project/server';
4+
5+
let defaultTransport = (
6+
`smtps://${configs.gmail[process.env.NODE_ENV].username}%40gmail.com:` +
7+
`${configs.gmail[process.env.NODE_ENV].password}@smtp.gmail.com`
8+
);
9+
10+
export default (transport = defaultTransport) => {
11+
let transporter = nodemailer.createTransport(transport);
12+
return {
13+
sendMail: (mailOptions) => new Promise((resolve, reject) => {
14+
mailOptions = assign(
15+
{},
16+
configs.mailOptions.default,
17+
configs.mailOptions[process.env.NODE_ENV],
18+
mailOptions
19+
);
20+
transporter.sendMail(mailOptions, (err, info) => {
21+
if (err) {
22+
return reject(err);
23+
}
24+
return resolve(info);
25+
});
26+
}),
27+
};
28+
};

0 commit comments

Comments
 (0)