-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
97 lines (72 loc) · 2.88 KB
/
server.js
File metadata and controls
97 lines (72 loc) · 2.88 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var express = require('express');
var app = express();
var path = require("path");
var ejs = require("ejs");
var logger = require('morgan');
var nodemailer = require('nodemailer');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var multer = require('multer'); // v1.0.5
var upload = multer(); // for parsing multipart/form-data
// create reusable transporter object using the default SMTP transport
// view engine setup
app.set('views', path.join(__dirname, ''));
app.set('view engine', 'ejs');
app.engine('html', ejs.renderFile);
app.use(logger('dev'));
app.use(bodyParser.json())
app.use(methodOverride());
app.use(bodyParser.urlencoded({ // parse application/x-www-form-urlencoded
extended: true
}));
app.use(express.static(path.join(__dirname, '')));
app.use(express.static(path.join(__dirname, 'views')));
var transporter = nodemailer.createTransport('smtps://carolina.janedoe%40gmail.com:chutiyabangya@smtp.gmail.com');
// setup e-mail data with unicode symbols
app.get('/', function (req, res) {
res.contentType('text/html');
res.render('index.html', {title: "rudra_acs"});
});
app.post('/email', upload.array(),function (req, res) {
//console.log("Inside email");
var params = req.body.params;
//console.log(req.body);
params = JSON.parse(params);
//console.log(JSON.stringify(params));
var card = '<b> Contact Card</b> <br /> Name: ' + params.content.first_name;
card += "<br/> Last Name: " + params.content.first_name;
card += "<br/> Phone: " + params.content.phone;
card += "<br/> Email: " + params.content.email;
card += "<br/> Address: " + params.content.address;
card += "<br/> City: " + params.content.city;
card += "<br/> State: " + params.content.State;
card += "<br/> Zip: " + params.content.zip;
card += "<br/> URL: " + params.content.url;
var card_text = 'Contact Card Name: ' + params.content.first_name;
card_text += "Last Name: " + params.content.first_name;
card_text += "Phone: " + params.content.phone;
card_text += "Email: " + params.content.email;
card_text += " Address: " + params.content.address;
card_text += " City: " + params.content.city;
card_text += "<br/> State: " + params.content.state;
card_text += "<br/> Zip: " + params.content.zip;
card_text += "<br/> URL: " + params.content.url;
var mailOptions = {
from: 'carolina.janedoe@gmail.com', // sender address
to: params.to, // list of receivers
subject: 'Contact', // Subject line
text: card_text, // plaintext body
html: card// html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
//console.log('Message sent: ' + info.response);
res.send(true);
});
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});