mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Added a new mailservice
This commit is contained in:
1
server/.gitignore
vendored
1
server/.gitignore
vendored
@@ -2,3 +2,4 @@ node_modules/
|
|||||||
scripts/
|
scripts/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
mongo_config.js
|
mongo_config.js
|
||||||
|
mailconfig.js
|
||||||
|
|||||||
@@ -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"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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,18 +91,31 @@ 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) {
|
||||||
|
let transporter = nodemailer.createTransport(mailconfig);
|
||||||
|
|
||||||
|
transporter.verify(function(error, success) {
|
||||||
|
if (error) {
|
||||||
|
res.sendStatus(500);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
var from = req.body.from;
|
var from = req.body.from;
|
||||||
var message = req.body.message;
|
var message = req.body.message;
|
||||||
sendmail({
|
var msg = {
|
||||||
from: from,
|
from: 'no-reply@zoff.no',
|
||||||
to: 'contact@zoff.no',
|
to: 'contact@zoff.no',
|
||||||
subject: 'ZOFF: Contact form webpage',
|
subject: 'ZOFF: Contact form webpage',
|
||||||
|
text: message,
|
||||||
html: message,
|
html: message,
|
||||||
}, function(err, reply) {
|
replyTo: from
|
||||||
if(err) {
|
}
|
||||||
res.sendStatus(500);
|
transporter.sendMail(msg, (error, info) => {
|
||||||
} else {
|
if (error) {
|
||||||
res.sendStatus(200);
|
res.send("failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.send("success");
|
||||||
|
transporter.close();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user