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.64k stars 340 forks source link

CSS is ignored if you don’t have a text.ejs #12

Closed natesilva closed 11 years ago

natesilva commented 11 years ago

If your template doesn’t have a text.ejs file, then your style.css is ignored.

My understanding is that style.css is used to add inline styles to the HTML version of your e-mail (that is, html.ejs), so it should work regardless of whether text.ejs is present or not.

To reproduce

var path           = require('path')
  , templatesDir   = path.join(__dirname, 'templates')
  , emailTemplates = require('email-templates');

emailTemplates(templatesDir, function(err, template) {
  template('pasta-dinner', {pasta: 'Spaghetti'}, function(err, html, text) {
    console.log('html is:', html);
  });
});

The HTML output should be the same as before, including the inlined <h1> style.

Acutal results

Styles from style.css are not present.

Regards, Nate

ralyodio commented 11 years ago

I believe it sends multipart/alternative emails, which requires a text version. You can generate a text version from html if you don't want to explicity define a text.ejs.

    transport.sendMail({
      from: 'Spicy Meatball <spicy.meatball@spaghetti.com>',
      to: locals.email,
      subject: 'Mangia gli spaghetti con polpette!',
      html: html,
      generateTextFromHTML: true
natesilva commented 11 years ago

Hi @chovy,

I discovered the problem while using generateTextFromHTML. But by that time, you’ve already called template(…) and it’s already generated your HTML, ignoring style.css.

My workaround was to create a blank text.ejs.

But it should use your style.css when generating the HTML, even if you have not created a text.ejs file, blank or not.

Regards, Nate