-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.babel.js
81 lines (71 loc) · 2.55 KB
/
server.babel.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
73
74
75
76
77
78
79
80
81
let express = require('express');
let mailer = require('express-mailer');
const app = express();
const bodyParser = require('body-parser');
const nodeMailer = require('nodemailer');
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static('public'));
/*mailer.extend(app,{
from: '[email protected]',
host:'smtp.zoho.com',
secureConnection: false,
port: 465,
transportMethod: 'SMTP',
auth: {
user: '[email protected]',
pass: 'ibjdjljv120062009'
}
});*/
let transporter = nodeMailer.createTransport({
host: 'smtp.yandex.ru',
port: 465,
secure: true, //true for 465 port, false for other ports
auth: {
user: '[email protected]',
pass: 'ibjdjljv120062009'
}
});
app.post('/sentemail', function (req, res) {
if(req.body.name && req.body.email){
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
if(pattern.test(req.body.email)){
let mailOptions = {
from: '"Work" <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: 'Work', // Subject line
text: "name: "+req.body.name+ " email: "+ req.body.email + " message: "+req.body.mess, // plain text body
html: '<div>'+"name: "+req.body.name+ " email: "+ req.body.email + " message: "+req.body.mess+'</div>' // html body
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
res.status(400).send({success: false})
} else {
res.status(200).send({success: true});
}
});
/*app.mailer.send('email',{
to: '[email protected]',
subject: "test",
message: "name: "+req.body.name+ " email: "+ req.body.email + " message: "+req.body.mess
}, function(err){
if(err){
res.statusCode = 400;
res.send(err);
console.log(err);return
}
res.send('email sent');
});*/
}else{
res.statusCode = 400;
res.send('Error');
}
}else{
res.statusCode = 400;
res.send('Error '+req.body.name +' '+ req.body.email);
}
});
app.listen(process.env.PORT || 3000);