Message from JavaScript discussions

September 2018

— Would you change something?

— 

This is what I get {"name":"David","email":"emailemail.com","message":"Hola, esto es una prueba"}

— Codepen.io

— Https://en.wikipedia.org/wiki/TempleOS

— I have a problem with nodemailer. I get 2 messages instead of one

— Any idea?

— Post code?

— Var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');

// Create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })

app.use(express.static('static_content'));

app.post('/es/enviar', urlencodedParser, function (req, res) {
const output = `
<p>You have a new contact request</p>
<h3>Contact Details</h3>
<ul>
<li>Name: ${req.body.name}</li>
<li>Email: ${req.body.email}</li>
<li>Subject: ${req.body.subject}</li>
</ul>
<h3>Message</h3>
<p>${req.body.message}</p>
`;

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({

service:'hotmail',
auth: {
user: process.env.EMAIL_USER, // generated ethereal user
pass: process.env.EMAIL_PASSWORD/ // generated ethereal password
},
tls: {
rejectUnauthorized: false
}
});

// setup email data with unicode symbols
let mailOptions = {
from: '"Nodemailer Contact" <email1hotmail.com>', // sender address
to: 'email2hotmail.com', // list of receivers
subject: 'Node Contact Request', // Subject line
text: 'Hello world?', // plain text body
html: output // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));

res.render('contact', { msg: 'Email has been sent' });
});
});

app.listen(8080, () => console.log('Server started...'));

Message permanent page

— Maybe your browser is hitting the endpoint twice?

— I don't know, it ends after sending the second email

— Server started...
Message sent: <78707965-127f-0c3f-93f1-cf32331c5658hotmail.com>
Preview URL: false
Message sent: <394a12f1-272e-534e-93f8-bf268f1a5971hotmail.com>
Preview URL: false

Message permanent page

— Those are the messages