title: How to use handlebars with nodemailer to send email?
body: <p>I am using nodemailer to send emails using the following <a href="https://github.com/mart-jansink/nodemailer-express-handlebars" rel="nofollow noreferrer">nodemailer-express-handlebars</a> plugin. I used this {dead blog post} as reference</p>
  <p>The code is compiling the <code>welcome</code> template but is not using the <code>layout</code></p>
  <p>My code is as below:</p>
  <pre><code>var nodemailer = require('nodemailer');
  var mg = require('nodemailer-mailgun-transport');
  var hbs = require('nodemailer-express-handlebars');
  
  var config = {auth: {api_key: &quot;key-xxx&quot;,domain: &quot;mydomain.com}}
  var nodemailerTransport = nodemailer.createTransport(mg(config));
  
  var options = {
      viewEngine: {
          extname: '.handlebars',
          layoutsDir: 'views/email/',
          defaultLayout : 'layout',
      },
      viewPath: 'views/email/'
  }
  
  nodemailerTransport.use('compile', hbs(options));
  
  nodemailerTransport.sendMail({
          from: 'from@mydomain.com',
          to: 'to@gmail.com',
          subject: 'Welcome to the XXX',
          template: 'welcome'
      }, function (err, results) {
          if (err) console.log('Error: ' + err);
          else console.log('Response: ' + results);
  });
  </code></pre>
  <p>My <code>layout.handlebars</code> has the following code</p>
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  {{&gt; _header }}
      {{{body}}}
  {{&gt; _footer }}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>