-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
53 lines (43 loc) · 1.27 KB
/
server.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
var express = require('express');
var nodemailer = require('nodemailer');
//var config = require('./config.js');
var app = express();
var smtpTransport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
// enter your gmail account
user: 'GMAIL_USER',
// enter your gmail password
pass: 'GMAIL_PASS'
}
});
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.sendfile('./public/index.html');
});
app.get('/send', function (req, res) {
var mailOptions = {
to: req.query.to,
subject: 'Contact Form Message',
from: "Contact Form Request" + "<" + req.query.from + '>',
html: "From: " + req.query.name + "<br>" +
"User's email: " + req.query.user + "<br>" + "Message: " + req.query.text
}
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function (err, response) {
if (err) {
console.log(err);
res.end("error");
} else {
console.log("Message sent: " + response.message);
res.end("sent");
}
});
});
app.listen(8080, function (err) {
if (err) {
console.log(err);
} else {
console.log("Listening on port on 8080");
}
});