Send parameters nodemailer, email-template-v2, hbs.

0

I'm using nodemailer to send emails, and email-template-v2 to send an HTML format, my purpose is to send some variables as a reference, payment and currency by email, but I really do not know how, I did not like to show it in my template .hbs, in fact I tried but I did not succeed; I leave my code to see if you can help me:

let users = [{
    name: "fulano", //mensaje.customer_info.name,
    email: "[email protected]", //mensaje.customer_info.email,



}];

let mensaje = {
    amount: 500,
    currency: "MXN",
}
let ref = "02584587631";

function sendEmail(obj) {
    return transporter.sendMail(obj);
}

function loadTemplate(templateName, contexts) {
    let template = new EmailTemplate(path.join(__dirname, 'templates', templateName));
    return Promise.all(contexts.map((context) => {
        return new Promise((resolve, reject) => {
            template.render(context, (err, result) => {
                if (err) reject(err);
                else resolve({
                    email: result,
                    context,
                });
            });
        });
    }));
}

loadTemplate('welcome', users, mensaje, efer).then((results) => {
    console.log(results)
    return Promise.all(results.map((result) => {
        sendEmail({
            to: result.context.email,
            from: 'PAGOS ELECTRONicos',
            subject: result.email.subject,
            html: result.email.html,
            text: result.email.text,
        });
    }));
}).then(() => {
    console.log('Yay!');
    res.json({
        ok: true,
    })
});

This would be my hbs:

<html>
    <head>
        <link href="./conekta/styles.css" media="all" rel="stylesheet" type="text/css" />
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
        <style>
            /* Reset -------------------------------------------------------------------- */
*    { margin: 0;padding: 0; }
body { font-size: 14px; }

/* OPPS --------------------------------------------------------------------- */

h3 {
    margin-bottom: 10px;
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
}

.opps {
    width: 496px; 
    border-radius: 4px;
    box-sizing: border-box;
    padding: 0 45px;
    margin: 40px auto;
    overflow: hidden;
    border: 1px solid #b0afb5;
    font-family: 'Open Sans', sans-serif;
    color: #4f5365;
}

.opps-reminder {
    position: relative;
    top: -1px;
    padding: 9px 0 10px;
    font-size: 11px;
    text-transform: uppercase;
    text-align: center;
    color: #ffffff;
    background: #000000;
}

.opps-info {
    margin-top: 26px;
    position: relative;
}

.opps-info:after {
    visibility: hidden;
     display: block;
     font-size: 0;
     content: " ";
     clear: both;
     height: 0;

}

.opps-brand {
    width: 45%;
    float: left;
}

.opps-brand img {
    max-width: 150px;
    margin-top: 2px;
}

.opps-ammount {
    width: 55%;
    float: right;
}

.opps-ammount h2 {
    font-size: 36px;
    color: #000000;
    line-height: 24px;
    margin-bottom: 15px;
}

.opps-ammount h2 sup {
    font-size: 16px;
    position: relative;
    top: -2px
}

.opps-ammount p {
    font-size: 10px;
    line-height: 14px;
    
}

.opps-reference {
    margin-top: 14px;
}

h1 {
    font-size: 27px;
    color: #000000;
    text-align: center;
    margin-top: -1px;
    padding: 6px 0 7px;
    border: 1px solid #b0afb5;
    border-radius: 4px;
    background: #f8f9fa;
}

.opps-instructions {
    margin: 32px -45px 0;
    padding: 32px 45px 45px;
    border-top: 1px solid #b0afb5;
    background: #f8f9fa;
}

ol {
    margin: 17px 0 0 16px;
}

li + li {
    margin-top: 10px;
    color: #000000;
}

a {
    color: #1155cc;
}

.opps-footnote {
    margin-top: 22px;
    padding: 22px 20 24px;
    color: #108f30;
    text-align: center;
    border: 1px solid #108f30;
    border-radius: 4px;
    background: #ffffff;
}

        </style>
    </head>
    <body>
        <div class="opps">
            <div class="opps-header">
                <div class="opps-reminder">Ficha digital. No es necesario imprimir.</div>
                <div class="opps-info">
                    <div class="opps-brand"><img src='https://scontent.fgdl5-1.fna.fbcdn.net/v/t1.15752-9/47056285_340117119902573_3179407570167136256_n.png?_nc_cat=101&_nc_ht=scontent.fgdl5-1.fna&oh=10f53ec6795c1da7930f186c61e01c89&oe=5C6CB506' alt="OXXOPay"></div>
                    <div class="opps-ammount">
                        <h3>Monto a pagar</h3>
                        <h2>{{ @mensaje.amount }}  <sup> {{ @mensaje.currency }}</sup></h2>
                        <p>OXXO cobrará una comisión adicional al momento de realizar el pago.</p>
                    </div>
                </div>
                <div class="opps-reference">
                    <h3>Referencia</h3>
                    <h1>{{ ./efer }}</h1>
                </div>
            </div>
            <div class="opps-instructions">
                <h3>Instrucciones</h3>
                <ol>
                    <li>Acude a la tienda OXXO más cercana. <a href="https://www.google.com.mx/maps/search/oxxo/" target="_blank">Encuéntrala aquí</a>.</li>
                    <li>Indica en caja que quieres realizar un pago de <strong>OXXOPay</strong>.</li>
                    <li>Dicta al cajero el número de referencia en esta ficha para que tecleé directamete en la pantalla de venta.</li>
                    <li>Realiza el pago correspondiente con dinero en efectivo.</li>
                    <li>Al confirmar tu pago, el cajero te entregará un comprobante impreso. <strong>En el podrás verificar que se haya realizado correctamente.</strong> Conserva este comprobante de pago.</li>
                </ol>
                <div class="opps-footnote">Al completar estos pasos recibirás un correo de <strong>PAGOS ELECTRONIOS</strong> confirmando tu pago.</div>
            </div>
        </div>  
    </body>
</html>

Greetings

    
asked by Pedro Buccellati 27.11.2018 в 05:15
source

0 answers