keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.64k stars 2.21k forks source link

Mandrill: Enquery does not send email notification #1441

Closed poliveira89 closed 8 years ago

poliveira89 commented 9 years ago

I have configured my .env file to which container Mandrill environment variables. And when I execute node keystone I don't receive any error.

But for some reason when I submit a new Enquiry I don't receive any notification email, it isn't even sent though Mandrill API as far I can see on their dashboard.

I tried to append some debug messages on the code. I added this code to models/Enquiry.js on line 34:

this.sendNotificationEmail(function() {
    console.log(arguments);
    console.log('sent email order');
});

This appeared on the Terminal:

...

GET /keystone/enquiries 200 863.394 ms
{ '0':
   { [Error: ENOENT, open '/home/vagrant/keystone/templates/emails/enquiry-notification/email.jade']
     errno: 34,
     code: 'ENOENT',
     path: '/home/vagrant/keystone/templates/emails/enquiry-notification/email.jade' },
  '1': null }
sent email order
POST /contact 200 210.989 ms

...

I have looked into it and I do not have /home/vagrant/keystone/templates/emails/enquiry-notification/email.jade but instead I got /home/vagrant/keystone/templates/emails/enquiry-notification.hbs with the following content:


<p>Needs implementation</p>

Anyone here already tried to use Mandrill? And can used successfully?

PS: Giving some context:

peterpme commented 9 years ago

Hey, it looks like you are using handlebars. Unfortunately, there is an issue with this. I haven't had a chance to put together a PR yet, but it's coming.

In the mean time, try this out inside of Enquiry.js (model)

new keystone.Email({
    templateExt: 'hbs',
    templateEngine: require('express-handlebars'),
    templateName: 'enquiry-notification'
  }).send({
    to: admins,
    from: {
      name: 'yourproject@gmail.com,
      email: 'contact@gmail.com'
    },
    subject: 'New Enquiry for Project Name',
    enquiry: enquiry
  }, callback);

I seem to be using require('handlebars') in my project right now, but I did notice keystone's generator uses express-handlebars. If you seem to have an error with express-handlebars, just replace it with handlebars

peterpme commented 9 years ago

See https://github.com/keystonejs/generator-keystone/pull/109

sylvainlap commented 9 years ago

I got the same problem, whatever the template engine. I think you don't copy the templates in the correct subfolder : https://github.com/keystonejs/generator-keystone/issues/110

peterpme commented 9 years ago

I use the keystone generator to scaffold out a project. It could be as simple as that but I remember debugging this awhile ago and tracing it down to a view engine issue.

hatzipanis commented 8 years ago

I hope this finds someone well. I was implementing notifications in a new project when I stumbled across this problem and after a short while realised we had solved this before with the following snippet.

Add to keystone.js:

// Switch Keystone Email defaults to handlebars 
keystone.Email.defaults.templateExt = 'hbs';
keystone.Email.defaults.templateEngine = require('handlebars');
peterpme commented 8 years ago

Thanks @hatzipanis this is a great place to put it!

mxstbr commented 8 years ago

I'll close this since the question was answered by @hatzipanis!