Calling a NodeMailer.js via Javascript (AJAX)

0

Hello, I wonder if it is possible to run a nodemailer via javascript (AJAX).
Because error returns and I can not debug (because this is on the server).
Is this the right way to call the file?
Thank you

The code for NodeMailer.js

var nodemailer = require("nodemailer");

var transporter = nodemailer.createTransport({
    host: "someHost",
    port: 465,
    secure: true,
    auth: {
        user: "[email protected]",
        pass: "password"
    }
});

var mailOptions = {
    from: '"Você" <[email protected]>',
    to: "[email protected]",
    subject: "Nodejs - Teste para o tutorial ??",
    text: "O teste foi efectuado com sucesso"
}

transporter.sendMail(mailOptions, function(err, info){
    if(err){
        console.log(err); // Não retorna este console
    }else{
        console.log("Mensagem enviada com sucesso"); //Este também não
    }
});

And this is the JavaScript way trying to run the Node file

function enviaEmail() {
    setLoadingBoxDisplay("block");
    $.ajax({
        url: "../../scripts/nodeMailer.js",
        async: true,
        dataType: "json",
        type: "GET",
        success: function (data) {
            console.log("Sucess");
        },
        complete: function () {
            setLoadingBoxDisplay("none");
        },
        error: function (data) {
            console.log("Fail");
            //var exc = data.responseJSON;
            //window.location.reload();
        }
    });
}
    
asked by anonymous 05.10.2018 / 13:27

0 answers