email-templates: Templates not being accessed?

I’m using this library but when I see the email preview, it only it shows “from”, “to”, “messageid” and “date”. It doesn’t have a subject and body like your preview example. It also doesn’t send when I change the send property to true.

I think the template isn’t being acquired properly so I did a ‘console.log(email.getTemplatePath());’ but it shows ‘TypeError: Path must be a string. Received undefined’. I’m not sure why thats happening as my structure is:

.
├── helpers
  ├── email.js
  └── emails
    └── signup_consumer
        ├── html.pug
        └── subject.pug

my code is:

const email = new Email({
    message: {
        from: 'email@mail.com' 
    },
    send: true,
    transport: {
        jsonTransport: true
    }
});
    email
        .send({
            template: 'signup_consumer',
            message: {
                to: user.email
            },
            locals: {
                name: 'exampleuser',
                sitelink: 'example.com',
            }
        })
        .then(console.log)
        .catch(console.error);
    //console.log(email.getTemplatePath());

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 32

Commits related to this issue

Most upvoted comments

It was looking for the path on ‘root/emails’ instead of in ‘root/helpers/emails’. I changed the path manually on email.config.views.root:

const email = new Email({
    message: {
        from: 'example@example.com'
    },
    views: {
        root: path.join(__dirname, 'emails')
    },
}

My mistake, I thought it would look from current directory not from root. Feel free to remove this issue.