Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //Lets require/import the HTTP module
  2. var http = require('http');
  3. var nodemailer = require('nodemailer');
  4. var xmlescape = require('xml-escape');
  5.  
  6. //Lets define a port we want to listen to
  7. const PORT=10001;
  8. var transporter = nodemailer.createTransport("SMTP",{
  9. host: 'localhost',
  10. port: 25,
  11. auth: {
  12. user: "frank@frank.com",
  13. pass: "admin"
  14. }
  15. });
  16. //We need a function which handles requests and send response
  17. function handleRequest(r, s){
  18.  
  19. var body = "";
  20. r.on('readable', function() {
  21. body += r.read();
  22. });
  23. r.on('end', function() {
  24. console.log(body);
  25. s.write("OK");
  26. s.end();
  27. });
  28. var mailOptions = {
  29. from: '"Communications" <communications@ottawawolves.ca>', // sender address
  30. to: 'communications@ottawawolves.ca', // list of receivers
  31. subject: 'Hello', // Subject line
  32. html: body // body
  33. };
  34. transporter.sendMail(mailOptions, function(error, info){
  35. if(error) {
  36. return console.log(error);
  37. }
  38. console.log('eMail sent: ' + xmlescape(body));
  39. }
  40. );
  41. }
  42.  
  43. //Create a server
  44. var server = http.createServer(handleRequest);
  45.  
  46. //Lets start our server
  47. server.listen(PORT, function(){
  48. //Callback triggered when server is successfully listening. Hurray!
  49. console.log("Server listening on: http://localhost:%s", PORT);
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement