sending email with nodemailer

0

I am making an application with angularjs and I have a form of contact with name, email, phone and message.

I need the contents of this form to go to the client's email and I'm trying to use the nodemailer but I'm not sure.

I created a structure as follows:

root:     | index.html     | js:         | script.js

Inside the scrirpt js I put the code below:

var nodemailer = require('nodemailer');

var transportador = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: '[email protected]',
        pass: 'futebol11'
        }
    });

exports.send = function(){

    var configuracoes = {
        from: 'Seu Nome <[email protected]>',
        to: 'Nome do Destinatário <[email protected]>, Outra Pessoa <[email protected]>',
        subject: 'Assunto do Email',
        text: 'Conteúdo do email em texto',
        html: '<h1>Conteúdo do email em HTML</h1>'
    };

    transportador.sendMail(configuracoes, function(error, info) {
        if (error) {
            console.log(error);
        } else {
            console.log('Email enviado ' + info.response);
        }
    });
}

I do not know how to call the upload file from the submit or an event on the button.

Can anyone help me?

    
asked by anonymous 29.06.2017 / 21:12

2 answers

0

I use the nodemailer-smtp-transport library along with the nodemailer lib. The send script I use in my projects is this one:

const nodemailer = require("nodemailer"),
     smtpTransport = require('nodemailer-smtp-transport');


const smtpConfig = smtpTransport({
    host: "smtp.seuhost.com",
    port: 587,
    ignoreTLS: true,
    secure : true,
    tls: {
        rejectUnauthorized: true
    },
    auth: {
        user: "Seu login",
        pass: "sua senha"
    }
});

const transporter = nodemailer.createTransport(smtpConfig);

const message  = {
    from: "Seu Nome ",
    to: "Nome do Destinatário ",
    subject: "Assunto do Email",
    text: "Conteúdo do email em texto",
    html: "<h1>Conteúdo do email em HTML</h1>",
    headers: {
        'X-Laziness-level': 1000
    }
};


transporter.sendMail(message, function(error, info) {               
    if (error) {
        console.log(error);
    } else {
        console.log('Email enviado ' + info.response);
    }
});
    
02.08.2017 / 22:49
0

I believe you will have to insert the script into a Controller from the index.html page. Add the email function to the controller scope.

Example:

$scope.sendMail = function {    

    transportador.sendMail(configuracoes, function(error, info) {
        if (error) {
            console.log(error);
        } else {
            console.log('Email enviado ' + info.response);
        }
    });
 }

in index.html insert the button: ng-click=sendMail()

    
21.07.2017 / 23:13