Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
natesilva opened this issue Oct 23, 2012 · 2 comments · Fixed by #17
Closed

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

natesilva opened this issue Oct 23, 2012 · 2 comments · Fixed by #17

Comments

@natesilva
Copy link

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

  • Create a project. npm install email-templates.
  • Create a directory called templates and copy the entire pasta-dinner example template there (including html.ejs, text.ejs and style.css).
  • Run the following app:
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);
  });
});
  • Note that everything works as expected, and the <h1> style is inlined.
  • Now delete templates/pasta-dinner/text.ejs.
  • Run the app again.

Expected results

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
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants