I am trying to send the data from form on react.js to email with help of nodemailer.
I've done everything right as it was in documentation, however there is probably some issue with my server (Node.js)
Here is error that i'm getting
Proxy error: Could not proxy request /api/form from localhost:3000 to https://localhost:3001.
In my package.json from client application i have such dependency as "proxy":"https://localhost:3001"
, it was in the tutorial that i've watched.
In my react application everything should be fine so i will not provide my react code.
Here is my node.js server
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const cors = require('cors');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(cors());
app.get('/', ()=> {
resizeBy.send('welcome to hell')
})
app.post('/api/form', (req,res)=> {
let data = req.body;
let smtpTransport = nodemailer.createTransport({
service:'gmail',
port:465,
auth:{
user:'####@gmail.com',
pass:'#####'
}
});
let mailOptions = {
from:data.email,
to:'[email protected]',
subject:`Message from ${data.name}`,
html:` <h3>Information</h3>
<ul>
<li> Name ${data.name} </li>
<li> Last name ${data.lastName} </li>
<li> Email ${data.name} </li>
</ul>
<h3>Message</h3>
<p>${data.message}</p>
`
};
smtpTransport.sendMail(mailOptions, (error, response) => {
error?response.send(error):response.send('Success')
})
smtpTransport.close()
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, ()=> {
console.log(`server is running at port ${PORT}`)
})
question from:
https://stackoverflow.com/questions/65901095/internal-server-error-500-node-js-when-trying-to-send-an-email-with-nodemailer 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…