-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (51 loc) · 1.35 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
const express = require('express');
const nodemailer = require('nodemailer');
const config = process.env.NODE_ENV === 'production'
? process.env
: require('./local');
const app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
const {
MAILGUN_USER,
MAILGUN_PASS,
PORT,
} = config;
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.post('/complete', function (req, res) {
console.error('req.body', req.body);
// console.error('req', req);
var transporter
, message;
transporter = nodemailer.createTransport({
service: 'Mailgun',
auth: {
user: MAILGUN_USER,
pass: MAILGUN_PASS
}
});
message = {
from: 'YourServer ',
to: 'leifdalan@gmail.com', // comma separated list
subject: `${req.body.name} Completed!`,
text: 'Text contents.',
html: `
<h1>${req.body.name} Completed!</h1>
<p>It took this many seconds: ${req.body.seconds_seeding}</p>
`
};
transporter.sendMail(message, function(error, info){
if (error) {
console.log(error);
} else {
res.send('cool.')
console.log('Sent: ' + info.response);
}
});
});
app.listen(PORT, function () {
console.log('Example app listening on port 3000!');
});