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

The mail is sent on both Windows and Linux, but templates is working only on Windows. #356

Closed llagerlof closed 5 years ago

llagerlof commented 5 years ago

Hi devs. I am having a problem with templates.

email-templates version: 5.0.4
node version on Windows: 10.15.1
node version on Linux: 8.10.0
OS: Windows 10 and Linux (Ubuntu)

The problem:

The body and subject templates is working on Windows. On Linux is being ignored.

The situation:

My script sendmymail.js send emails using one body's template and one subject's template. The directory structure is exactly like below:

/script/sendmymail.js
/script/emails/send_ok/html.pug
/script/emails/send_ok/subject.pug

Instantiate the mail with smtp, etc. This authenticate succefully with my smtp server (but I changed the authentication data for this issue purpose):

  const email = new Email({
    message: {
      from: 'a_valid_sender@email.com'
    },
    send: true,
    transport: {
    host: "smtp.email.com",
    port: 587,
    secure: false,
    auth: {
      user: "a_valid_sender",
      pass: "the_mail_server_password"
    }
    }
  });

The send method:

  email
    .send({
      template: 'send_ok',
      message: {
        to: 'myemail@email.com'
      },
      locals: {
        data: 'test data',
      }
    })
    .then(sentMailSuccess)
    .catch(console.error);
}

html.pug

p This is the body of #{data}.

subject.pug

= `This is the subject of ${data}`

When I run node sendmymail.js on Windows, the e-mail is sent succefully (the recipient receives the email), with the correct body and subject.

When I run node sendmymail.js on Linux, the e-mail is sent succefully too (the recipient receives the email), but with an empty body and subject.

Just a note: I already checked the directories permission. The owner of all files and directories is the same user who runs the node command, with all the read/write permission set.

Any ideas what could be happening? Thank you.

niftylettuce commented 5 years ago

Run with DEBUG=email-templates node app.js and report back with output

On Wed, Apr 10, 2019 at 11:11 AM Lawrence Lagerlof notifications@github.com wrote:

Hi devs. I am having a problem with templates.

email-templates version: 5.0.4 node version on Windows: 10.15.1 node version on Linux: 8.10.0 OS: Windows 10 and Linux (Ubuntu)

The problem:

The body and subject templates is working on Windows. On Linux is being ignored.

The situation:

My script sendmymail.js send emails using one body's template and one subject's template. The directory structure is exactly like below:

/script/sendmymail.js /script/emails/send_ok/html.pug /script/emails/send_ok/subject.pug

Instantiate the mail with smtp, etc. This authenticate succefully with my smtp server:

const email = new Email({ message: { from: 'a_valid_sender@email.com' }, send: true, transport: { host: "smtp.email.com", port: 587, secure: false, auth: { user: "a_valid_sender", pass: "the_mail_server_password" } } });

The send method:

email .send({ template: 'send_ok', message: { to: 'myemail@email.com' }, locals: { data: 'test data', } }) .then(sentMailSuccess) .catch(console.error); }

html.pug

p This is the body of #{data}.

subject.pug

= This is the subject of ${data}

When I run node sendmymail.js on Windows, the e-mail is sent succefully (the recipient receives the email), with the correct body and subject.

When I run node sendmymail.js on Linux, the e-mail is sent succefully too (the recipient receives the email), but with an empty body and subject.

Just a note: I already checked the directories permission. The owner of all files and directories is the same user who runs the node command, with all the read/write permission set.

Any ideas what could be happening? Thank you.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/356, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hWV1Xy8PoJzHBgIrR5tWSVTHmhzOks5vfg1JgaJpZM4cnt4U .

llagerlof commented 5 years ago

Thanks. I think I found a strange problem in this log. This is the linux debug. The Windows hasn't this error:

2019-04-10T16:39:41.968Z email-templates templateExists { Error: ENOENT: no such file or directory, stat '/script/emails/send_ok/text.pug'
  cause: 
   { Error: ENOENT: no such file or directory, stat '/script/emails/send_ok/text.pug'
     errno: -2,
     code: 'ENOENT',
     syscall: 'stat',
     path: '/script/emails/send_ok/text.pug' },
  isOperational: true,
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/script/emails/send_ok/text.pug' }

However I haven't this text.pug in Windows, neither in Linux.

niftylettuce commented 5 years ago

What is your config? Your full email templates configuration (including directory paths for your templates and how you set up)?

llagerlof commented 5 years ago

My config? Nothing special I think. I just installed the email-templates with npm install (not global), and wrote the script above.

I load the lib using const Email = require('email-templates');. Normal.

niftylettuce commented 5 years ago

I can't help you unless you share a full config or code snippet, along with what transport you're using to send mail. I'm guessing your transport is to blame for not being cross platform compatible?

On Wed, Apr 10, 2019 at 12:03 PM Lawrence Lagerlof notifications@github.com wrote:

My config? Nothing special I think. I just installed the email-templates with npm install (not global), and wrote the script above.

I load the lib using const Email = require('email-templates');. Normal.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/356#issuecomment-481776657, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hSM3L4MJFtcAGHFu5XfILQG73hVCks5vfhlqgaJpZM4cnt4U .

llagerlof commented 5 years ago

I am sending using SMTP.

The transport I am using is the embedded email-templates' nodemailer. And the setup I am using is just as described below (I changed the credentials and the SMTP address):

  const email = new Email({
    message: {
      from: 'a_valid_sender@email.com'
    },
    send: true,
    transport: {
    host: "smtp.email.com",
    port: 587,
    secure: false,
    auth: {
      user: "a_valid_sender",
      pass: "the_mail_server_password"
    }
    }
  });

Maybe this is related to Issue #348 ?

niftylettuce commented 5 years ago

See my comment here https://github.com/niftylettuce/email-templates/issues/348#issuecomment-481788711

llagerlof commented 5 years ago

Understood. It's for debugging purposes, but the real catch here is why the email-templates doesn't find my body and subject templates in Linux, but finds it in Windows? It's the same script, same directory structure, same credentials.

niftylettuce commented 5 years ago

Can you share a reproducible code base in a GitHub repository somewhere and invite me to it?

llagerlof commented 5 years ago

Ok, I will do it.

llagerlof commented 5 years ago

I moved the project folder to another parent directory, and the error isn't happening anymore. Mystery.

Well, that's it. If this happen again, I will be back. Thanks.