forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.67k stars 337 forks source link

No content passed error #335

Closed ProductOfAmerica closed 5 years ago

ProductOfAmerica commented 5 years ago

Hello,

I've been developing my server with this package for a while now on my local machine. Today I moved my server to a digital ocean droplet, and I'm receiving the error:

Error sending register email: Error: No content was passed for subject, html, text, nor attachments message props. Check that the files for the template "register" exist.

This is really weird to me because my file system is exactly the same on my server as it is on my local machine, and it's been working fine on my local machine. My server is running Ubuntu 16.0.4.

TLDR; works fine on local, error on server, same file structure. Any ideas?

My structure:

And my code in index.js:

const email = new Email({
  send: true,
  preview: false,
  message: {
    from: process.env.EMAIL_USER
  },
  transport: {
    secure: true,
    host: 'smtp.gmail.com',
    port: 465,
    auth: {
      user: process.env.EMAIL_USER,
      pass: process.env.EMAIL_PASS
    }
  }
});

email.send({
      template: 'register',
      message: {
        to: destEmail
      },
      locals: {
        timestamp: new Date().toUTCString()
      }
    }).then(() => {
      console.log("Sent register email.")
    }).catch((err) => {
      console.error("Error sending register email: " + err)
    });
niftylettuce commented 5 years ago

@ProductOfAmerica can you please share the content of the files html.pug and subject.pug? The reason is because they are rendering as being blank. If you want to keep them private you could email them to me, niftylettuce@gmail.com. Please do this ASAP so I can make sure that this is not a core bug from the last version of this package published on NPM.

ProductOfAmerica commented 5 years ago

@niftylettuce email sent

niftylettuce commented 5 years ago

@ProductOfAmerica what version of email-templates are you on by the way?

niftylettuce commented 5 years ago

@ProductOfAmerica I think you need to specify a root option because you may not be running node from the root folder of where the app is.

const root = path.join(__dirname, 'emails');
const email = new Email({
  views: { root }
});

Right now it uses path.resolve('emails') to find the directory.

Perhaps we can fix this so it recursively finds the root directory of the project using pkg-dir and then use that directory + emails.

ProductOfAmerica commented 5 years ago

@niftylettuce Unfortunately that didn't work. However, the solution was this:

const email = new Email({
  views: { root: __dirname }
});
harveyconnor commented 5 years ago

I am having the same issue, I can resolve the path but appear to get the same error. Error: No content was passed for subject, html, text, nor attachments message props. I have logged the props and they get to the function just fine, it seems there is an issue resolving the templates.

bkdev98 commented 5 years ago

Add babel --copy-files option to build command fixed the issue for me. Detail: https://stackoverflow.com/a/35033177

harveyconnor commented 5 years ago

@bkdev98 yep, I saw somewhere in the past. Thanks for your answer.

ghost commented 5 years ago

Hi all, I'm still running into this issue - anyone has a solution?

niftylettuce commented 5 years ago

@Carrein have you tried debugging? see https://github.com/niftylettuce/email-templates#debugging

ghost commented 5 years ago

@niftylettuce Thanks I was using uppercases (which worked on a mac since its case insensitive but failed on linux).

zcmgyu commented 4 years ago

I used the below command to debug to find out the reason.

DEBUG=email-templates node index.js

It points out that it has no such file or directory. And that dir doesn't include emails in the path.

templateExists { [Error: ENOENT: no such file or directory, stat '~~~/research/send-email/mars/subject.pug']

So, I removed emails like the following directory structure.

.
├── app.js
└── mars
    ├── html.pug
    └── subject.pug

It worked for me as expected.

kyledavelaar commented 2 years ago

I had this issue in a test because I was using a fake test template that didn't exist in my templates folder. It used to not throw this error on an older version (5.0.1) but now does on 9.0.0. Once I pointed it to a template that was in my templates folder the error went away.