Giter VIP home page Giter VIP logo

node-premailer's Introduction

node-premailer

A simple api wrapper for http://premailer.dialect.ca, a great tool for inlining css before you send an email.

node-premailer simplifies api integration by calling the Premailer API to inline css styles (and other options such as removing comments, classes and ids), then retrieving the generated html and text from their respective URLs before passing them to your callback.

Install

  npm install premailer-api

Or from source:

  git clone git://github.com/JedWatson/node-premailer.git
  cd node-premailer
  npm link

Usage

var premailer = require('premailer-api');

var emailTemplate = `
  <html>
    <head>
      <title>My Email</title>
      <style type="text/css">
        a { color: #336699; }
      </style>
    </head>
    <body>
      Styles inlined with
      <a href="http://premailer.dialect.ca">Premailer</a> via
      <a href="https://github.com/JedWatson/node-premailer">node-premailer</a>.
    </body>
  <html>`;

premailer.prepare({ html: emailTemplate }, function (err, email) {
  if (err) throw err;
  res.send(email.html);
});

Options

  • premailerAPI (string) The URL of the premailer API. If you're running your own, replace this. Defaults to http://premailer.dialect.ca/api/0.1/documents
  • html (string) The html of the email to parse and inline styles.
  • url (string) The url of the email to fetch then parse and inline styles.
  • fetchHTML (boolean) Whether to fetch the parsed HTML (you'll usually want this). Defaults to true.
  • fetchText (boolean) Whether to fetch the auto-generated text version (disable this if you are providing your own). Defaults to true.
  • See http://premailer.dialect.ca/api for full list of options. All options have aliases for node.js style variable names.
    • adapter
    • baseUrl || base_url
    • lineLength || line_length
    • linkQueryString || link_query_string
    • preserveStyles || preserve_styles
    • removeIds || remove_ids
    • removeClasses || remove_classes
    • removeComments || remove_comments

License and Credits

MIT Licensed. Copyright Jed Watson 2016.

A big thank you to Dialect for Premailer, and for making the API freely available.

There's also a web version available here: http://premailer.dialect.ca

And you can check out the source code for Premailer itself here: https://github.com/alexdunae/premailer/

node-premailer's People

Contributors

bmoeskau avatar jbuck avatar jedwatson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-premailer's Issues

Error when having more than 10 files

When I have more than 10 files I get this error:

(node) warning: possible EventEmitter memory leak detected. 11 finish listeners added. Use emitter.setMaxListeners() to increase limit.

I found a work around. I just created a grunt jub for every file but It might be good to have the normal behavior.

If the project is still maintained I might have the time to make a pull request

Premailer returned an unkown server error

We have been getting the following error multiple times today, starting a few hours ago. These appeared even though we didn't make any changes to our mailer system at all.

Premailer returned an unkown server error

Thanks

SyntaxError: Unexpected token I in JSON at position 0

I don't know what to do against this issue. It seems like I MOST OF THE TIMES get a broken JSON from node-premailer? I am always using the same parameters including URL, but most of the times I get the error message and 1 out of 5 times, the result variable contains the result. Does anybody else have this problem?

This is how I execute it:

 premailer.prepare({ html: resBody }, function (err, result){
   console.log(results) //undefined
})

And this is the error I get:

SyntaxError: Unexpected token I in JSON at position 0
at JSON.parse ()
at Request.handlePremailerResponse [as _callback] (/home/pi/newsfire/node_modules/premailer-api/premailer.js:103:23)
at Request.self.callback (/home/pi/newsfire/node_modules/request/request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/home/pi/newsfire/node_modules/request/request.js:1081:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/home/pi/newsfire/node_modules/request/request.js:1001:12)
at Object.onceWrapper (events.js:290:19)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
drin
/home/pi/newsfire/lib/newsfire.js:114
html: result.html // html body
^

TypeError: Cannot read property 'html' of undefined
at model.Query.PageLog.find.sort.limit.find (/home/pi/newsfire/lib/newsfire.js:114:29)
at /home/pi/newsfire/node_modules/kareem/index.js:264:21
at /home/pi/newsfire/node_modules/kareem/index.js:127:16
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.