How to send message with nodemailer and email-templates?
<p>I try to send email with nodemailer and email-templates. Now I have example from here <a href="https://github.com/niftylettuce/node-email-templates/blob/master/examples/nodemailer/index.js" rel="nofollow noreferrer">example email templates</a>. But when I check this code, I have error <code>a promise was rejected with a non-error: [object Undefined]</code></p>
<p>Help me please. This is my code</p>
<pre><code>var nodemailer = require('nodemailer');
var EmailTemplate = require('email-templates').EmailTemplate;

exports.sendOne = function () {
var templatesDir = config.templatesDir;
var template = new EmailTemplate(path.join(templatesDir, 'hello.jade'))
var transport = nodemailer.createTransport({
    service: config.service,
    auth: config.auth
});

// An example users object with formatted email function
var locals = {
    email: 'example@mail.com',
    name: {
        first: 'Mamma',
        last: 'Mia'
    }
}

// Send a single email
template.render(locals, function (err, results) {
    if (err) {
        return console.error(err)
    }

    transport.sendMail({
        from: 'Spicy Meatball &lt;spicy.meatball@spaghetti.com&gt;',
        to: locals.email,
        subject: 'Mangia gli spaghetti con polpette!',
        html: results.html,
        text: results.text
    }, function (err, responseStatus) {
        if (err) {
            return console.error(err)
        }
        console.log(responseStatus.message)
    })
})

}
</code></pre>
<p>My error :</p>
<pre><code>Warning: a promise was rejected with a non-error: [object Undefined]
at /home/project/node_modules/email-templates/lib/util.js:31:39
at FSReqWrap.oncomplete (fs.js:82:15)
From previous event: ...
</code></pre>
<p>Tell me please how to fix this error? thanks!</p>
<p><strong>UPDATE code</strong></p>
<pre class="lang-js prettyprint-override"><code>exports.sendOne = function () {
  var nodemailer = require(&quot;nodemailer&quot;);

  var transport = nodemailer.createTransport({
    service: &quot;gmail&quot;,
    auth: {
      user: &quot;test@gmail.com&quot;,
      pass: &quot;123456&quot;,
    },
  });

  var EmailTemplate = require(&quot;email-templates&quot;).EmailTemplate;
  var path = require(&quot;path&quot;);

  var templateDir = path.join(__dirname, &quot;templates&quot;, &quot;hello&quot;);

  var myTemplate = new EmailTemplate(templateDir);

  var locals = {
    email: &quot;example@mail.com&quot;,
    name: {
      first: &quot;Mamma&quot;,
      last: &quot;Mia&quot;,
    },
  };

  myTemplate.render(locals, function (err, result) {
    // result.html
    // result.text
    if (err) {
      return console.error(err);
    }

    transport.sendMail(
      {
        from: &quot;Spicy Meatball &lt;spicy.meatball@spaghetti.com&gt;&quot;,
        to: locals.email,
        subject: &quot;Mangia gli spaghetti con polpette!&quot;,
        html: results.html,
        text: results.text,
      },
      function (err, responseStatus) {
        if (err) {
          return console.error(err);
        }
        console.log(responseStatus.message);
        return responseStatus; // return from status or as you need;
      }
    );
  });
};
</code></pre>
<p>I updated my code but now i have error <code>{ [Error: ENOENT: no such file or directory, stat '/path-to-my-project/templates/hello''] errno: -2, code: 'ENOENT', syscall: 'stat', path: '/path-to-my-project/templates/hello' }</code></p>