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

Calling render(locals) Throws Error #255

Closed mr-White closed 6 years ago

mr-White commented 6 years ago

I followed the guide to upgrading. It states that one must call email.render(locals) to render a template.

I get an error stating it's expecting a String. After some tinkering, I found that String to be the name of the template.

I did get email-templates module working. It works as follows:

const email = new Email({
  juice: true,
  juiceResources: {
    preserveImportant: true,
    webResources: {
      relativeTo: path.join(__dirname, '../../public')
    }
  },
  transport: {
    jsonTransport: true
  },
  views: {
    root: templateDir // this is the same variable as version 2, works great as is
  },
});

return email.render(template, parsableData); // return a promise with locals to be parsed as second arg

Once that promise resolves, I create a new object and use mailgun-js to send the rendered HTML email. Side question, is there a way to get the render() to return an object of HTML, Subject, and Text? If not, no worries, I just need to adjust my setup a little.

mr-White commented 6 years ago

One other thing, I had to create index.pug instead of html.pug for my template's HTML code. Not sure if it's still using index.pug instead, but I got to get working on something else now so I'll check back another time.

niftylettuce commented 6 years ago

It's using index. Why not use email.send?

On Oct 23, 2017 6:10 PM, "Michael Lage" notifications@github.com wrote:

One other thing, I had to create index.pug instead of html.pug for my template's HTML code. Not sure if it's still using index.pug instead, but I got to get working on something else now so I'll check back another time.

— 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/255#issuecomment-338811760, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hefJTKKcEbvATeFvGLWwyRvZqdXHks5svQ7MgaJpZM4QDgbY .

mr-White commented 6 years ago

@niftylettuce I tried at first, but I'm using Mailgun's API as my mailer.

Simple answer, it was less work to get sending emails again when using the module mailgun-js to send the emails via Mailgun's API.

niftylettuce commented 6 years ago

Why can't you use the Mailgun transport for Nodemailer?

On Oct 23, 2017 6:26 PM, "Michael Lage" notifications@github.com wrote:

@niftylettuce https://github.com/niftylettuce I tried at first, but I'm using Mailgun's API as my mailer.

Simple answer, it was less work to get sending emails again when using the module mailgun-js to send the emails via Mailgun's API.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/255#issuecomment-338815036, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hV59Vz8alrP87f6b9Fock8ofcVKwks5svRKmgaJpZM4QDgbY .

mr-White commented 6 years ago

@niftylettuce I can use Mailgun transport for Nodemailer. I haven't before - got any code examples?

mr-White commented 6 years ago

@niftylettuce I'm guessing something like this would work? https://www.npmjs.com/package/nodemailer-mailgun-transport

niftylettuce commented 6 years ago

You don't even need that. It's built in!

https://nodemailer.com/smtp/well-known/

Just specify "Mailgun" as the "service".

On Mon, Oct 23, 2017 at 6:30 PM, Michael Lage notifications@github.com wrote:

@niftylettuce https://github.com/niftylettuce I'm guessing something like this would work? https://www.npmjs.com/package/ nodemailer-mailgun-transport

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-templates/issues/255#issuecomment-338815684, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hbft08I5HAQonDAXYKfmA23PdalMks5svRNsgaJpZM4QDgbY .

-- @niftylettuce

mr-White commented 6 years ago

@niftylettuce that sounds awesome! I got some other work that I need to finish first, but once I'm done, I'll give it a shot.

Thank you!!

mr-White commented 6 years ago

@niftylettuce that was easy!

Thank you, again! The code is a lot cleaner :D