-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.js
More file actions
61 lines (45 loc) · 1.16 KB
/
service.js
File metadata and controls
61 lines (45 loc) · 1.16 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
// this is the core of the app
// read the html file
// send it by email
const fs = require('fs');
const Send = function(input) {
return new Promise((resolve, reject) => {
const send = require('gmail-send')(input);
send({},function(err, data) {
if(err) {
return reject(err);
}
resolve(data);
})
})
}
const readFile = function(path){
return new Promise((resolve, reject) => {
fs.readFile(path, "utf8", function(err, data) {
if (err) {
return reject(err);
}
resolve(data.toString());
})
})
}
module.exports.readAndSend = function(params) {
console.log('read html and send starting');
let emailData = {};
Object.assign(emailData, params.email);
let filePath = params.filePath
if(!filePath){
filePath = 'mail.html';
}
readFile(filePath).then(html => {
console.log('file read succeeded');
emailData.html = html;
Send(emailData).then(() => {
console.log('The email has been sent')
}).catch(err => {
console.error('error trying to send the email ', err)
});
}).catch(err => {
console.error('error trying to read file ', err)
});
}