Sending emails with nodemailer, nodejs

0

I am trying to send emails through nodemailer and a simple application. Somehow, when trying to post to the server, it seems that a connection error leaks, but I can not know what exactly happens. This is the code; router.post ('/ sendmail', function (req, res, next) { ...   var transporter = nodemailer.createTransport ("SMTP", {        host: "smtp-mail.outlook.com", // hostname         secureConnection: false, // TLS requires secureConnection to be false         port: 587, // port for secure SMTP         auth: {            user: "[email protected]",            pass: "password"

    },
    tls: {
        ciphers:'SSLv3'
    }
});



// setup e-mail data with unicode symbols
var mailOptions = {
    from: 'Username \u26AD <username@server>', // sender address

     to: '[email protected]', // list of receivers
    subject: subject,
    text: text_content, // plaintext body
    html: html_content,
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log( info);
    res.end('Sent :)');
});

This is the call ajax a / sendMail

$.ajax({
                type: "POST",
                url: "/sendmail",
                dataType: 'json',
                data: {
                    owner: '56fab5a69835c6dc22b4603d',
                    name: $scope.reservation.name,
                    email: $scope.reservation.email,
                    notes: $scope.reservation.province+': ' + notes,
                    phone: $scope.reservation.phone,
                    origin: "albertotaboada.com configurador",
                    ip: ip
                },
                success: function (data, textStatus, xhr) {
                    $scope.form_status = "success";
                }, error: function () {
                    $scope.form_status = "success";
                }
            });

The error that jumps in the money to do POST:

{ [Error: connect ECONNREFUSED 127.0.0.1:587]

code: 'ECONNREFUSED',   errno: 'ECONNREFUSED',   syscall: 'connect',   address: '127.0.0.1',   port: 587,   stage: 'init'}

Can someone help me please? greetings!

    
asked by Toni Rodriguez 11.11.2017 в 22:37
source

1 answer

0

I think you have some configuration missing, add this to your configuration:

var transport = nodemailer.createTransport("SMTP", {
    host: "smtp-mail.outlook.com", // hostname
    secureConnection: false, // TLS requires secureConnection to be false
    port: 587, // port for secure SMTP
    auth: {
        user: "[email protected]",
        pass: "password"
    },
    tls: {
        ciphers:'SSLv3'
    }
});

Another option would be to use nodemailer-wellknown : D

var transport = nodemailer.createTransport("SMTP", {
        service: "Hotmail",
        auth: {
            user: "[email protected]",
            pass: "password"
        }
    });

Greetings

    
answered by 13.01.2018 в 01:00