-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
71 lines (60 loc) · 2.38 KB
/
server.js
File metadata and controls
71 lines (60 loc) · 2.38 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
require('dotenv').config()
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
app.use(bodyParser.json({limit:'50mb'})) // handle json data
app.use(bodyParser.urlencoded({ extended: true, limit:'50mb' })) // handle URL-encoded data
require('dotenv').config();
//static folder
app.use('/public', express.static(path.join(__dirname, 'public')));
console.log(process.env.email)
console.log(process.env.pass)
app.post('/api/uploadContactForm', (req, res) => {
const output = `
<h3>Thank you for contacting us!</h3>
<p> We will be responding shortly to your request. Please verify the below information is correct.</p>
<ul>
<li>First Name: ${req.body.firstname}</li>
<li>Last Name: ${req.body.lastName}</li>
<li>Email: ${req.body.email}</li>
<li>URL: ${req.body.textarea}</li>
<li>Description: ${req.body.description}</li>
</ul>
`;
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.ethereal.email', //I DO NOT HAVE A HOST
auth: {
user: process.env.email, // generated ethereal user
pass: process.env.pass // generated ethereal password
},
tls:{
rejectUnauthorized:false
}
});
// setup email data with unicode symbols
const mailOptions = {
from: '"CreateMe Contact Form" <jessbennett924@gmail.com>', // sender address
to: req.body.email, // list of receivers
subject: "Contact Request", // Subject line
text: 'Hello world?', // plain text body
html: output // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
});
});
const port = 4000;
app.listen(port, () => `Server running on port ${port}`)
;