Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

reactjs - Internal server error 500 node.js when trying to send an email with nodemailer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...