-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (51 loc) · 1.62 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
require("dotenv").config()
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
var email;
app.use(express.static('public'));
var io = require('socket.io')(server);
io.sockets.on('connection',
function (socket) {
console.log("We have a new client: " + socket.id);
socket.on('email',
function(data) {
var data=JSON.parse(data)
email=data.email;
var name=data.name
var content=JSON.stringify(data.data).split(",")[1]
var mailOptions = {
from: '[email protected]',
to: email,
subject: 'Greenlab Certificate',
html: '<h2>Hello<h2><p>Congratulations </br>You have successfully completed the course </br></p>',
attachments: [{
filename: name+".pdf",
contentType: 'application/pdf',
content:content,
encoding: 'base64',
}]
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent to : ' + email);
socket.emit("succed",'Email sent to : ' + email +" on "+new Date().toDateString()+" at "+new Date().toTimeString())
}
});
}
);
})
server.listen(3000, () => {
console.log('listening on *:3000');
});