906landing
Version:
906 LAnding PAge
57 lines (49 loc) • 1.56 kB
JavaScript
var nodemailer = require("nodemailer");
var express = require("express");
var smtpTransport = require("nodemailer-smtp-transport")
var bodyParser = require('body-parser')
var app = express();
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
var smtpConfig = nodemailer.createTransport((smtpTransport({
host: 'smtp.pontopr.com',
port: 25,
secure: false,
tls: {
rejectUnauthorized: false
}, // use SSL
auth: {
user: 'francisco.silva@pontopr.com',
pass: 'PontoPr@0315'
}
})));
// Declare a static directory:
app.use(express.static(__dirname + '/'));
//routing logic to tell our app what is supposed to do when Request comes from browser
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.post('/send', function(req, res) {
var envelope = req.body.name + ' ' + req.body.from;
var mailOptions = {
from: envelope,
to: "francisco.silva@pontopr.com",
subject: req.body.subject,
text: req.body.text,
html: req.body.text
}
smtpConfig.sendMail(mailOptions, function(error, response) {
if (error) {
console.log(error);
res.end("error");
} else {
console.log(response);
res.end("sent");
}
});
});
//creation of our Server
var port = process.env.PORT || 3000;
app.listen(port, function() {});