diff --git a/src/libs/middlewares/email.js b/src/libs/middlewares/email.js index 7e0403d423cebd1bd0a8c6c31f57eef5773860f4..610826fc3401231b3e146378515e8ba028acf1cb 100644 --- a/src/libs/middlewares/email.js +++ b/src/libs/middlewares/email.js @@ -23,7 +23,8 @@ transporter.verify(function(error, success) { }); const mailOptions = { - from: config.email.from + from: config.email.from, + to: config.email.from }; module.exports = function send(options, cb) { diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index c96266b09f260fb65813ea5c71ca0aeef4a9347c..31fc9257c397fabc7d2eacd7a9348ee163b1f982 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -128,6 +128,8 @@ const disciplines = require(`${libs}/routes/disciplines`); const universityLocalOffer = require(`${libs}/routes/universityLocalOffer`); +const message = require(`${libs}/routes/message`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); @@ -183,4 +185,5 @@ api.use('/microregion', microregion); api.use('/location', location); api.use('/disciplines', disciplines); api.use('/universityLocalOffer', universityLocalOffer); +api.use('/message', message); module.exports = api; diff --git a/src/libs/routes/message.js b/src/libs/routes/message.js new file mode 100644 index 0000000000000000000000000000000000000000..81292a39b319d0ca3f357fbf118886567c13d6ad --- /dev/null +++ b/src/libs/routes/message.js @@ -0,0 +1,47 @@ +/* +Copyright (C) 2021 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +const express = require('express'); + +const messageApp = express.Router(); + +const email = require(`../middlewares/email`); + +messageApp.post('/', (req, res, next) => { + var reqName = JSON.parse(req.body.name) + var reqEmail = JSON.parse(req.body.email) + var reqContents = JSON.parse(req.body.contents) + + let mailOptions = { + from: `"${reqName} <${reqEmail}>"`, + text: reqContents + } + + email(mailOptions, (err, info) => { + if(err) { + log.error(err); + res.json({msg: 'Undelivered Contact Mail'}); + } + log.info(`Message ${info.messageId} sent: ${info.response}`); + res.json({msg: 'Contact Mail Successfully Delivered'}); + }); +}) + +module.exports = messageApp;