-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (31 loc) · 1.02 KB
/
server.js
File metadata and controls
39 lines (31 loc) · 1.02 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
const express = require('express')
const bodyParser = require('body-parser')
const mailgun = require('mailgun-js')
const app = express();
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static(" "));
const api_key = '4c9a496cb46106cfdc3f7ac82dfb15fe-0f1db83d-4218afc8';
const domain = 'sandbox7f199e758eda4baaaaf2bf262bfff736.mailgun.org';
const mg = mailgun({apiKey: api_key, domain: domain});
app.get('/', (request, response)=>{
response.sendFile(__dirname + "/app.js")
})
app.post('/', (request, response)=>{
const email = request.body.email;
const data = {
from: 'Jeffy <jeffysambabu@gmail.com>',
to: email,
subject: 'Welcome to Daily Insider!',
text: 'Welcome to our newest Daily Insider subscriber.'
};
mg.messages().send(data, function (error, body) {
if(error){
console.log(error);
} else {
console.log(body);
}
});
})
app.listen(3000, ()=>{
console.log("Server is running on port 3000.")
})