image embedding in a email nodemailer

Viewed 29

I have this code, im starting with node:

exports.FindHappyB = function(req, res) {

    //cron.schedule('* * * * *', () => {
    const Email = require("email-templates");

    const transporter = nodemailer.createTransport({
      service: "gmail",
      auth: {
        user: "xxxxx@gmail.com",
        pass: "xxxxx"
      }
    });

    const email = new Email({
      message: {
        from: "xxxxx@gmail.com"
      },
      // uncomment below to send emails in development/test env:
      send: true,
      preview: false,
      transport: transporter
    });



    email
      .send({
        template: "mars",
        message: {
          to: "xxxxxxxxxx@gmail.com"
        },
        locals: {
          name: "Rodolfo",
          dir: __dirname
      ,
        }

        
    
      })
      .then(console.log("se envio"))
      .catch(console.error);


  //    });
};

my route is api/controlador/cumple, and I have an image in public folder, an the template in "emails/mars" in the same level the controlador here the code of html.pug

<!DOCTYPE html>
<html lang="es">  
  <head>    
    <meta charset="UTF-8">
    <meta name="title" content="Título de la WEB">
    <meta name="description" content="Descripción de la WEB">    
  </head>  
<body>
<div style="background-image: url('imagen.jpg');  background-repeat: no-repeat;  background-size: auto; text-align:center; padding: 570px;">


                <h2> #{name}</h2>
                <h1>#{dir}</h1>


</div>

</body>

</html>

I dont know how put the image that i have in public, sorry for teh mistake, the email send fien but the image dont show up

0 Answers
Related