Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. var api_id = 'your_api_id';
  2. var api_key = 'your_api_key';
  3. var recipientEmailAddress = 'your_email@your_domain.com';
  4.  
  5. var sendgrid = require("sendgrid")(api_id, api_key);
  6. var express = require('express');
  7. var app = express();
  8.  
  9. // Allow webserver to serve static files
  10. app.use(express.static(__dirname));
  11.  
  12. // Serve the web-form when the browser requests localhost:8080
  13. app.all('/', function (req, res) {
  14. res.sendFile('index.html', { root: __dirname });
  15. });
  16.  
  17. // Run this function when the web form is submitted.
  18. app.post('/email', function (req, res) {
  19. // Create email, set some attributes, and send it off!
  20. var email = new sendgrid.Email();
  21.  
  22. email.addTo(recipientEmailAddress);
  23. email.setFrom(req.query.address);
  24. email.setSubject(req.query.subject);
  25. email.setHtml(req.query.message);
  26.  
  27. sendgrid.send(email);
  28. });
  29.  
  30. // Give this app a port to listen to.
  31. app.listen(8080);
  32.  
  33. console.log('Listening to 8080');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement