javascript - Nodemailer: ERR_CONNECTION_RESET with AngularJS and NodeJS with POST - Stack Overflow

Following is the post data I am trying to send to NodeJS from AngularJS using POST method:$scope.doStuf

Following is the post data I am trying to send to NodeJS from AngularJS using POST method:

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

And following is the how I am receiving data on the server end using 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);
        }
    });
});

I am just trying to send email using nodemailer and I've been able to send the email alright. But I get a POST http://localhost:3000/send net::ERR_CONNECTION_RESET on the console once the request has been sent. Sometimes I also get POST http://localhost:3000/send net::ERR_EMPTY_RESPONSE on the console.

Could somebody help me understand that why do I get that on the console and how to resolve it?

Following is the post data I am trying to send to NodeJS from AngularJS using POST method:

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

And following is the how I am receiving data on the server end using 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);
        }
    });
});

I am just trying to send email using nodemailer and I've been able to send the email alright. But I get a POST http://localhost:3000/send net::ERR_CONNECTION_RESET on the console once the request has been sent. Sometimes I also get POST http://localhost:3000/send net::ERR_EMPTY_RESPONSE on the console.

Could somebody help me understand that why do I get that on the console and how to resolve it?

Share Improve this question edited Sep 4, 2014 at 21:29 skip asked Sep 4, 2014 at 21:19 skipskip 12.7k34 gold badges117 silver badges159 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You don't return a response from your route.

res.send(200)

Previously when i was working with nodemailer module, i also had same issues. It may be possibly some server mis-configuration because the code worked fine on my local server. And on live, it shows Error: connect ECONNREFUSED. I've tried a lot to resolve this issue, but, unsuccessful. So at last i switched to other module i.e. Mailer .
It has worked fine for me, you can give it a try.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745403216a4626195.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信