Beste meneer/mevrouw {client}, |
Helaas is de geldigheid van deze aanvraag verlopen. U kunt opnieuw een aanvraag indienen. |
Wilt u meer informatie? Dan kunt u mailen naar aanvraag@santander.nl. |
';
console.log(__dirname);
var mailOptions = {
from: 'rente.compensatie@santander.nl',
to: req.body.email,
subject: req.body.subject,
html: emailStruture
};
transporter.sendMail(mailOptions, function (error: any, info: any) {
if (error) {
console.log(error);
res.send(error);
} else {
console.log('Email sent: ' + info.response);
res.send('Email sent');
}
});
}
);
export { router as sendEmailRouter };
-----
import { NextFunction, Request, Response } from 'express';
import * as fs from 'fs';
import path from 'path';
async function basicAuth(req: Request, res: Response, next: NextFunction) {
// make authenticate path public
if (req.path === '/users/authenticate') {
return next();
}
// check for basic auth header
if (
!req.headers.authorization ||
req.headers.authorization.indexOf('Basic ') === -1
) {
return res.status(401).json({ message: 'Missing Authorization Header' });
}
const jsonString = fs.readFileSync(
path.resolve(__dirname, '../config/config.json'),
'utf-8'
);
const jsonData = JSON.parse(jsonString);
// verify auth credentials
const base64Credentials = req.headers.authorization.split(' ')[1];
const credentials = Buffer.from(base64Credentials, 'base64').toString(
'ascii'
);
const [username, password] = credentials.split(':');
const allowed =
username === jsonData.username && password === jsonData.password;
if (!allowed) {
return res
.status(401)
.json({ message: 'Invalid Authentication Credentials' });
}
next();
}
export { basicAuth };
----
import express from 'express';
import { json } from 'body-parser';
import { sendEmailRouter } from './routes/sendemail';
const app = express();
app.use(json({ limit: '25mb' }));
app.use(express.urlencoded({ limit: '25mb' }));
app.use(sendEmailRouter);
export { app };
---
import { app } from './app';
app.listen(3003, () => {
console.log('Listening in 3003');
});