Added a new mailservice

This commit is contained in:
Kasper Rynning-Tønnesen
2017-05-02 20:56:29 +02:00
parent ffe5a70f01
commit a53b484fad
3 changed files with 30 additions and 16 deletions

1
server/.gitignore vendored
View File

@@ -2,3 +2,4 @@ node_modules/
scripts/ scripts/
.DS_Store .DS_Store
mongo_config.js mongo_config.js
mailconfig.js

View File

@@ -12,12 +12,11 @@
"express-handlebars": "^3.0.0", "express-handlebars": "^3.0.0",
"express-subdomain": "^1.0.5", "express-subdomain": "^1.0.5",
"jimp": "^0.2.27", "jimp": "^0.2.27",
"lwip": "0.0.9",
"mongodb": "^2.0.27", "mongodb": "^2.0.27",
"mongojs": "^2.4.0", "mongojs": "^2.4.0",
"node-cryptojs-aes": "^0.4.0", "node-cryptojs-aes": "^0.4.0",
"nodemailer": "^4.0.1",
"request": "^2.72.0", "request": "^2.72.0",
"sendmail": "^1.1.1",
"socket.io": "^1.7.3", "socket.io": "^1.7.3",
"uniqid": "^4.1.1" "uniqid": "^4.1.1"
}, },

View File

@@ -1,7 +1,8 @@
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
const path = require('path'); const path = require('path');
var sendmail = require('sendmail')(); var nodemailer = require('nodemailer');
var mailconfig = require('./mailconfig.js');
router.use(function(req, res, next) { router.use(function(req, res, next) {
next(); // make sure we go to the next routes and don't stop here next(); // make sure we go to the next routes and don't stop here
@@ -90,20 +91,33 @@ router.route('/:user_name/:channel_name').get(function(req, res, next){
*/ */
router.route('/api/mail').post(function(req, res) { router.route('/api/mail').post(function(req, res) {
var from = req.body.from; let transporter = nodemailer.createTransport(mailconfig);
var message = req.body.message;
sendmail({ transporter.verify(function(error, success) {
from: from, if (error) {
to: 'contact@zoff.no', res.sendStatus(500);
subject: 'ZOFF: Contact form webpage', return;
html: message, } else {
}, function(err, reply) { var from = req.body.from;
if(err) { var message = req.body.message;
res.sendStatus(500); var msg = {
} else { from: 'no-reply@zoff.no',
res.sendStatus(200); to: 'contact@zoff.no',
subject: 'ZOFF: Contact form webpage',
text: message,
html: message,
replyTo: from
} }
}); transporter.sendMail(msg, (error, info) => {
if (error) {
res.send("failed");
return;
}
res.send("success");
transporter.close();
});
}
});
}); });
router.route('/').get(function(req, res, next){ router.route('/').get(function(req, res, next){