Merge pull request #37 from ohtuprojekti-ilmo/email

Email
This commit is contained in:
vasdf
2018-11-17 18:17:00 +02:00
committed by GitHub
3 changed files with 50 additions and 1 deletions
+2
View File
@@ -1,6 +1,7 @@
const topicsRouter = require('express').Router()
const db = require('../models/index')
const checkAdmin = require('../utils/middleware/checkAdmin').checkAdmin
const email = require('../utils/email')
const getRandomId = require('../utils/idGeneration').getRandomId
topicsRouter.post('/', (req, res) => {
@@ -12,6 +13,7 @@ topicsRouter.post('/', (req, res) => {
secret_id
})
.then(topic => {
email.sendSecretLink(topic.secret_id, topic.email)
res.status(200).json({ topic })
})
.catch(error => {
+10 -1
View File
@@ -14,9 +14,18 @@ let login = 'http://opetushallinto.cs.helsinki.fi/login'
let secret = 'secret'
//email config
let email = {
sender: 'Ohtuilmo Robot <noreply@helsinki.fi>',
host: 'smtp.helsinki.fi',
port: 587,
secure: false
}
module.exports = {
dbUrl,
port,
login,
secret
secret,
email
}
+38
View File
@@ -0,0 +1,38 @@
const config = require('./config')
const nodemailer = require('nodemailer')
function sendSecretLink(secretId, address) {
const options = {
to: address,
subject: 'Link to your Software Engineering Project topic submission',
html: '<a href="http://svm-45.cs.helsinki.fi:7000/topics/'+secretId+'">Click this link to view or edit your submission</a>'
}
send(options)
}
function send(options) {
const transporter = nodemailer.createTransport({
host: config.email.host,
port: config.email.port,
secure: config.email.secure
})
const mailOptions = {
from: config.email.sender,
to: options.to,
subject: options.subject,
text: options.text,
html: options.html
}
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error)
}
console.log('sent: ', info)
})
}
module.exports = {
sendSecretLink
}