-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (69 loc) · 2.04 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const express = require('express')
const basicAuth = require('express-basic-auth')
var app = express()
app.use(express.json())
/*app.use(basicAuth({
users: {'admin': 'ctrlalttec'},
challenge: true
}))
*/
const fetch = require('node-fetch')
const readline = require('readline-sync')
const nodemailer = require('nodemailer')
let email = readline.question("Email ")
let password = readline.question("Password ", {hideEchoBack: true})
var mailer = nodemailer.createTransport({
service: 'gmail',
auth: {
user: email,
pass: password
}
})
function sendMails(addresses, url, subject){
//for(let address of addresses){
fetch(url).then(data=>data.text()).then(content=>{
mailer.sendMail({
to: addresses,
subject: subject,
html: content
}, (error, info)=>{
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
})
})
//}
}
/*
async function getMails(){
return new Promise((resolve, reject)=>{
fetch('https://ctrl-alt-tec-members.herokuapp.com/members').then((data)=>data.json()).then((data)=>{
resolve(
data.map( l => ({
address: l['CORREO ELECTRONICO '],
name: l['NOMBRE (S)']
}) )
)
})
})
}
*/
app.get('/', async (req, res)=>{
//console.log(req.auth.user)
//let mails = await getMails()
//res.end(JSON.stringify(mails))
res.sendFile(__dirname+'/index.html')
})
app.get('/templates', (req, res)=>{
fetch('https://ctrl-alt-tec.github.io/Templates/templates.json').then(data=>data.json()).then(data=>{
res.end(JSON.stringify(data))
//console.log(data)
}).catch(err=>{console.log(err)})
})
app.post('/send', (req, res)=>{
sendMails(req.body.mails, req.body.url, req.body.subject)
})
app.listen(process.env.PORT || 8080, function(){
console.log("Your node js server is running")
})