nodemailer不停止发送邮件

我有一个简单的nodemailer安装程序发送电子邮件没有问题。 我唯一不知道的是如何阻止它一旦开始发送。 我点击发送,它发送一封电子邮件,但页面不断加载,很快我收到另一封电子邮件等。当然,它应该只发送一封电子邮件,并closures过程。

有人可以看到我在这里做错了吗?

var smtpTransport = nodemailer.createTransport('SMTP', { host: 'mail.francotanzarella.com', secureConnection: false, port: 587, auth: { user: 'contact@francotanzarella.com', pass: '***' } }); app.post('/contact', function(req, res) { var htmlTpl = '<h4>Message from' + ' ' + req.body.name + '</h4><p><span>' + req.body.email + '</span</p><p>' + req.body.message + '</p>'; mailOptions = { from: 'noreply@francotanzarella.com', to: 'contact@francotanzarella.com', subject: 'New message from francotanzarella.com', html: htmlTpl, debug: true } smtpTransport.sendMail(mailOptions, function(error, response) { if(error) { console.log(error) } else { console.log(response.message); } smtpTransport.close(); }); }); 

contact.ejs

 <form id="contact-form" method="POST" name="userForm" action="/contact" ng-submit="submitForm(userForm.$valid)" novalidate> <div class="row"> <div class="small-12 column"> <div class="row" ng-class="{ 'error' : userForm.name.$invalid && !userForm.name.$pristine && submitted }"> <div class="small-12 column"> <label for="name" class="inline">Name</label> </div> <div class="small-12 column"> <input type="text" id="name" name="name" placeholder="Your name" ng-model="name" required /> <small class="error" ng-show="userForm.name.$invalid && !userForm.name.$pristine">Please enter your name</small> </div> </div> <div class="row" ng-class="{ 'error' : userForm.email.$invalid && !userForm.email.$pristine && submitted }"> <div class="small-12 column"> <label for="email" class="inline">Email</label> </div> <div class="small-12 column"> <input type="email" id="email" name="email" placeholder="Your email" ng-model="email" required /> <small class="error" ng-show="userForm.email.$invalid && !userForm.email.$pristine">I need a valid email please</small> </div> </div> <div class="row" ng-class="{ 'error' : userForm.message.$invalid && !userForm.message.$pristine && submitted }"> <div class="small-12 column"> <label for="message" class="inline">Message</label> </div> <div class="small-12 column"> <textarea id="message" name="message" placeholder="Send me a message" ng-model="message" required></textarea> <small class="error" ng-show="userForm.message.$invalid && !userForm.message.$pristine">What? No message?</small> </div> </div> <div class="row"> <div class="small-12 column"> <button type="submit" class="button" ng-disabled="userForm.$invalid">send</button> </div> </div> </div> </div> <div id="form-response-container"> <div id="for-response-inner"> <h3 id="form-response"></h3> </div> </div> </form> 

好的,我解决了这个问题。 不知道这是否是正确的方法,但它的工作原理。 当邮件发送成功时,我基本上通过浏览器(200)。

 if(error) { res.send(500); } else { res.send(200); }