Bonjour,
Voila je rencontre un petit problème avec mon code.
const express = require('express'); //framework js
const bodyParser = require('body-parser'); //récuperer la data soumise avec HTTP POST
const exphbs = require('express-handlebars'); // template
const path = require('path');
const nodemailer = require('nodemailer'); // va chercher nodemailer
//----------------------------------------------------------------------------//
const app = express(); //Pour utiliser express via app
//View engine setup
app.engine('handlebars', exphbs()); // use template
app.set('view engine', 'handlebars'); // name view engine value handlebars
// Static folder
app.use('/public', express.static(path.join(__dirname, 'public'))); // This is a built-in middleware function in Express. It serves static files and is based on serve-static.
// Body parser Middleware
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.render('contact');
}); // Une requete via le get avec une rep
app.post('/send', (req, rep) => {
const output = `
<p>You have a new contact<p/>
<h3>Contact Details</h3>
<ul>
<li>Name: ${req.body.name}</li>
<li>Company: ${req.body.company}</li>
<li>Email: ${req.body.email}</li>
<li>Phone: ${req.body.phone}</li>
</ul>
<h3>Message</h3>
<p>${req.body.message}</p>
`;
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.orange.fr',
port: 25,
secure: false, // true for 465, false for other ports
auth: {
user: 'monadressegmail', // generated ethereal user
pass: 'monmotdepassegmail' // generated ethereal password
},
tls: {
rejectUnauthorized:false
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Nodemailer contact" <test@traversymedia.com>', // sender address
to: 'monadressemail', // 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(3000, () => console.log('Server started')); // ecoute via port 3000
{ Error: Invalid login: 550 5.7.0 Mot de passe invalide. Verifiez ou reinitialisez votre mot de passe sur orange.fr :
http://assistance.orange.fr/oid/78554#onglet3 [305]
at SMTPConnection._formatError (/home/nomdefamille/sites/labo/nodecontactform/node_modules/nodemailer/lib/smtp-connec
tion/index.js:591:19)
at SMTPConnection._actionAUTHComplete (/home/nomdefamille/sites/labo/nodecontactform/node_modules/nodemailer/lib/smtp
-connection/index.js:1320:34)
at SMTPConnection._responseActions.push.str (/home/nom defamille/sites/labo/nodecontactform/node_modules/nodemailer/li
b/smtp-connection/index.js:356:26)
at SMTPConnection._processResponse (/home/nomdefamille/sites/labo/nodecontactform/node_modules/nodemailer/lib/smtp-co
nnection/index.js:747:20)
at SMTPConnection._onData (/home/nomdefamillesites/labo/nodecontactform/node_modules/nodemailer/lib/smtp-connection/
index.js:543:14)
at Socket._socket.on.chunk (/home/nomdefamille/sites/labo/nodecontactform/node_modules/nodemailer/lib/smtp-connection
/index.js:495:47)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
code: 'EAUTH',
response: '550 5.7.0 Mot de passe invalide. Verifiez ou reinitialisez votre mot de passe sur orange.fr : http://ass
istance.orange.fr/oid/78554#onglet3 [305]',
responseCode: 550,
command: 'AUTH PLAIN' }
je ne comprend pas pourquoi orange me dit que le mot de passe n'est pas bon car j'utilise une adresse gmail
Bonjour.
Peut-être tout simplement parce que tu donnes les bon identifiants concernant Gmail, sauf que tu définis le smtp de Orange et non celui de Gmail ici : host: 'smtp.orange.fr'
.