-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
62 lines (57 loc) · 1.55 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
54
55
56
57
58
59
60
61
62
var express = require('express');
var nodemailer = require('nodemailer');
var app = express();
const { transporter } = require('./transporter');
/*
Here we are configuring our SMTP Server details.
STMP is mail server which is responsible for sending and recieving email.
*/
var smtpTransport = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
user: '',
pass: '',
},
});
/* const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: process.env.USER,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
refreshToken: process.env.REFRESH_TOKEN,
accessToken: process.env.ACCESS_TOKEN,
},
}); */
/*------------------SMTP Over-----------------------------*/
/*------------------Routing Started ------------------------*/
app.get('/', function (req, res) {
res.sendFile('index.html', {
root: __dirname,
});
});
app.get('/send', function (req, res) {
var mailOptions = {
from: 'Kathirr007 <[email protected]>',
to: req.query.to,
subject: req.query.subject,
text: req.query.text,
html: req.query.htmlContent,
};
console.log(mailOptions);
transporter.sendMail(mailOptions, function (error, response) {
if (error) {
console.log(error);
res.end('error');
} else {
console.log('Message sent...');
res.end('sent');
}
});
});
/*--------------------Routing Over----------------------------*/
app.listen(3000, function () {
console.log('Express Started on Port 3000');
});