-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 804 Bytes
/
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
const express = require('express');
const cors = require('cors');
const app = express();
const bodyParser = require('body-parser');
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Welcome Page
app.get('/', (req, res) => {
res.send('Welcome to the SendGrid Email Server | Łukasz Jędrasik')
console.log(process.env.SENDGRID_API_KEY);
});
// Email Page
app.post('/send', (req, res) => {
const msg = {
to: '[email protected]',
from: req.body.from,
subject: req.body.subject,
text: req.body.text
};
sgMail.send(msg);
res.send('');
});
app.listen(8080, () => console.log(`running on port 8080`));