Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var api_id = 'your_api_id';
- var api_key = 'your_api_key';
- var recipientEmailAddress = 'your_email@your_domain.com';
- var sendgrid = require("sendgrid")(api_id, api_key);
- var express = require('express');
- var app = express();
- // Allow webserver to serve static files
- app.use(express.static(__dirname));
- // Serve the web-form when the browser requests localhost:8080
- app.all('/', function (req, res) {
- res.sendFile('index.html', { root: __dirname });
- });
- // Run this function when the web form is submitted.
- app.post('/email', function (req, res) {
- // Create email, set some attributes, and send it off!
- var email = new sendgrid.Email();
- email.addTo(recipientEmailAddress);
- email.setFrom(req.query.address);
- email.setSubject(req.query.subject);
- email.setHtml(req.query.message);
- sendgrid.send(email);
- });
- // Give this app a port to listen to.
- app.listen(8080);
- console.log('Listening to 8080');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement