-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (59 loc) · 2 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var express = require("express");
// mail
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
var app = express();
var router = express.Router();
var path = __dirname + '/';
router.use(function (req,res,next) {
console.log("/" + req.method);
next();
});
router.get("/",function(req,res){
res.sendFile(path + "index.html");
});
app.use(express.static(path));
app.use("/", router);
//---- mail ----
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post('/send-email', (req, res) => {
const transporter = nodemailer.createTransport({
service: 'outlook',
auth: {
user: 'updevops@outlook.com.br',
pass: '12345678'
}
});
const { name, email, prof, message } = req.body;
if (!name || !email || !prof || !message) {
return res.send("<script>alert('Por favor, preencha todos os campos obrigatórios.'); window.location='/';</script>");
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
return res.send("<script>alert('Por favor, insira um endereço de e-mail válido.'); window.location='/';</script>");
}
const mailOptions = {
from: 'updevops@outlook.com.br',
to: prof,
cc: email,
bcc: 'seniorfullstackdevops@gmail.com',
subject: 'UP DevOps - Contato do Site',
text: `Nome: ${name}\nE-mail: ${email}\nMensagem:\n${message} \n\n© UP DevOps - Todos os direitos reservados.`,
replyTo: email
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Email sent error: ' + error);
return res.send("<script>alert('Erro ao tentar enviar mensagem.'); window.location='/';</script>");
} else {
console.log('Email sent: ' + info.response);
return res.send("<script>alert('Mensagem enviada com sucesso!'); window.location='/';</script>");
}
});
});
//---- mail ----
app.use(express.static(__dirname, { dotfiles: 'allow' } ));
app.listen(80, () => {
console.log('HTTP server escutando na porta 80');
})