2014-09-04 3 views
1

다음 POST와 AngularJS와 및 NodeJS와 ERR_CONNECTION_RESET가 POST 방법을 사용하여 AngularJS와에서 내가 NodeJS에 보내려고하고있는 포스트 데이터입니다 :Nodemailer :

$scope.doStuff = function(foo, bar) { 
    $http({method: 'post', url: '/send', data: {foo: foo, bar: bar}}). 
     success(function(data, status, headers, config) { 
      console.log(data); 
    }); 
}; 

을 그리고 다음과 같은 서버 측에서 어떻게 수신하고 데이터입니다 NodeJS를 사용하여 :

router.post('/send',function(req,res){ 

    var transporter = nodemailer.createTransport({ 
     service: 'Gmail', 
     auth: { 
      user: '[email protected]', 
      pass: 'foobar' 
     } 
    }); 
    var mailOptions = { 
     from: 'Foo Bar ✔ <[email protected]>', 
     to: req.body.foo, // list of receivers 
     subject: "Hello FooBar", 
     text: 'Hello ' + req.body.foo, 
     html: "<p>Hello FooBar, you rock!</p>" 
    }; 
    transporter.sendMail(mailOptions, function(error, info){ 
     if(error){ 
      console.log(error); 
     }else{ 
      console.log('Message sent: ' + info.response); 
     } 
    }); 
}); 

나는 단지 nodemailer를 사용하여 전자 메일을 보내려고하고 있으며 전자 메일을 올바르게 보낼 수있었습니다. 요청이 전송되면 콘솔에 POST http://localhost:3000/send net::ERR_CONNECTION_RESET이 표시됩니다. 가끔 콘솔에 POST http://localhost:3000/send net::ERR_EMPTY_RESPONSE도 표시됩니다.

누군가 나를 이해할 수 있도록 도움을 줄 수 있습니다. 왜 콘솔에서이를 어떻게 해결할 수 있습니까?

답변

3

경로에서 응답을 보내지 마십시오. 내가 nodemailer 모듈과 함께 일하고 이전

res.send(200) 
1

가, 나 또한 같은 문제가 있었다. 내 로컬 서버에서 코드가 제대로 작동했기 때문에 일부 서버 구성이 잘못되었을 수 있습니다. 그리고 라이브에서는 Error: connect ECONNREFUSED이 표시됩니다. 이 문제를 해결하기 위해 많은 노력을했지만 실패했습니다. 그래서 마지막으로 다른 모듈 즉 Mailer으로 전환했습니다.
그것은 나를 위해 잘 작동했습니다, 당신은 시도해 볼 수 있습니다.

+1

나는 '이 팬'이 아니지만 '나를 위해 일했다'. – Ravi

+0

https://github.com/Marak/node_mailer는 nodemailer에 찬성하여 반대되었습니다. – skip

관련 문제