Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lets require/import the HTTP module
- var http = require('http');
- var nodemailer = require('nodemailer');
- var xmlescape = require('xml-escape');
- //Lets define a port we want to listen to
- const PORT=10001;
- var transporter = nodemailer.createTransport("SMTP",{
- host: 'localhost',
- port: 25,
- auth: {
- user: "frank@frank.com",
- pass: "admin"
- }
- });
- //We need a function which handles requests and send response
- function handleRequest(r, s){
- var body = "";
- r.on('readable', function() {
- body += r.read();
- });
- r.on('end', function() {
- console.log(body);
- s.write("OK");
- s.end();
- });
- var mailOptions = {
- from: '"Communications" <communications@ottawawolves.ca>', // sender address
- to: 'communications@ottawawolves.ca', // list of receivers
- subject: 'Hello', // Subject line
- html: body // body
- };
- transporter.sendMail(mailOptions, function(error, info){
- if(error) {
- return console.log(error);
- }
- console.log('eMail sent: ' + xmlescape(body));
- }
- );
- }
- //Create a server
- var server = http.createServer(handleRequest);
- //Lets start our server
- server.listen(PORT, function(){
- //Callback triggered when server is successfully listening. Hurray!
- console.log("Server listening on: http://localhost:%s", PORT);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement