Initial commit
This commit is contained in:
49
index.js
Normal file
49
index.js
Normal file
@ -0,0 +1,49 @@
|
||||
const dotenv = require("dotenv");
|
||||
dotenv.config()
|
||||
const express = require("express");
|
||||
const bodyParser = require('body-parser');
|
||||
const nodemailer = require("nodemailer");
|
||||
const fs = require("fs");
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: "smtp-relay.brevo.com",
|
||||
port: 587,
|
||||
authMethod: "PLAIN",
|
||||
auth: {
|
||||
user: process.env.smtp_user,
|
||||
pass: process.env.smtp_pass,
|
||||
}
|
||||
});
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.use(express.static("assets"))
|
||||
app.use(bodyParser.urlencoded());
|
||||
|
||||
app.post("/post", (req, res) => {
|
||||
fs.writeFile(`./data/${req.body.firstname}-${req.body.lastname}.json`, JSON.stringify(req.body), (err) => {
|
||||
return res.send(err)
|
||||
})
|
||||
|
||||
transporter.sendMail({
|
||||
from: "Alumnihub <alumnihub@kocoder.xyz>",
|
||||
to: `${req.body.firstname} ${req.body.lastname} <${req.body.email}>`,
|
||||
envelope: {
|
||||
from: "alumnihub@kocoder.xyz",
|
||||
to: req.body.email,
|
||||
},
|
||||
subject: "Anmeldungs für's Absolvententreffen.",
|
||||
text: `Hallo ${req.body.firstname}!
|
||||
Du hast dich erfolgreich für das Absolvententreffen am X.Y.Z angemeldet! Hier findest du alle Details https://x.y!
|
||||
Bei Rückfragen bitte an: absolvententreffen@outlook.com wenden.
|
||||
`,
|
||||
}, (err, info) => {
|
||||
if (err) return res.send(err);
|
||||
});
|
||||
return res.send("Du wurdest erfolgreich angemeldet!");
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
});
|
Reference in New Issue
Block a user