-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (42 loc) · 1.01 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
var express = require('express');
var nodemailer = require('nodemailer');
var app = express();
// define SMTP for email sending
var smtpTransport = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
auth: {
user: "Your-Email@gmail.com",
pass: "User-Password"
}
});
// app routing
app.get('/', function(req, res){
res.sendfile('index.html');
});
app.get('/send', function(req, res){
var mailoptions = {
to: req.query.to,
subject: req.query.subject,
text: req.query.text
}
console.log(mailoptions);
smtpTransport.sendMail(mailoptions, function(error, response){
if(error){
console.log(error);
res.end("error");
} else {
console.log("Message Sent: " + response.message);
res.end("sent");
}
});
});
// server starts on port 3000
app.listen(3000, function(){
console.log("Server started on port: 3000");
console.log(" ");
console.log("Open your browser to: localhost:3000");
console.log(" ");
console.log("-------------------------------");
console.log(" ");
});