Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.

feature: automatically create plain-text version from html template to reduce spam score #42

Merged
merged 5 commits into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Usually, building HTML emails yourself is tedious. On top of that, add the need
6. [Paths](#paths)
7. [Sample file structure](#sample-file-structure)
8. [Logging](#logging)
9. [Plain-text](#plain-text)
6. [Version history](#version-history)
7. [Contributing](#contributing)

Expand All @@ -27,6 +28,7 @@ Usually, building HTML emails yourself is tedious. On top of that, add the need
- **SCSS support** using `node-sass` (opt-in).
- **Preview and debug** emails in development mode in your browser when developing.
- **Layouts** for re-using markup.
- **Auto Plain-text** automatically creates a plain text version from your html template for lower Spam score.

Help is appreciated in order to hammer out potential issues and bugs.

Expand Down Expand Up @@ -91,6 +93,8 @@ Please inspect the provided sample code for details.
templates: {}, // Required. A key-value hash where the keys are the template names. See more below.
helpers: {}, // Global helpers available for all templates.
layout: false // Global layout template.
settings:
plainText: true // Optional, defaults to true
}
```

Expand Down Expand Up @@ -439,8 +443,19 @@ and that will be used. The logger **must** support these methods:

Why not try [`meteor-logger`](https://github.com/lookback/meteor-logger)? :)

### Plain-text
By default, plain-text versions are automatically created from your html template and included in the final email. It's strongly advises to leave this option on, as it greatly reduces your emails' Spam score and the chance that your emails will end up in Spam folder of users. However, if you want to override this behaviour simply at this to `Mailer.init()`:

```coffeescript
Mailer.init(
settings:
plainText: false
)
```

## Version history

- `0.6.0` - Automatically create and include plain-text email version from your HTML templates
- `0.5.1` - Remove need for setting the `BUNDLE_PATH` environment variable ([#39](https://github.com/lookback/meteor-emails/pull/39)).
- `0.5.0` - Remove `node-sass` as hard dependency. SCSS support is now opt-in, by adding `chrisbutler:node-sass` to your app ([#35](https://github.com/lookback/meteor-emails/pull/35)).
- `0.4.6` - Fix paths on Windows in development mode.
Expand Down
12 changes: 12 additions & 0 deletions emails.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

TAG = 'mailer'

# used to make plain-text version from html version
htmlToText = Npm.require 'html-to-text'

# ## Setup

# Main exported symbol with some initial settings:
Expand All @@ -27,6 +30,7 @@ Mailer =
disabled: false
addRoutes: process.env.NODE_ENV is 'development'
language: 'html'
plainText: true

juiceOpts:
preserveMediaQueries: true
Expand Down Expand Up @@ -226,6 +230,14 @@ MailerClass = (options) ->
# Render HTML with optional data context.
try
opts.html = render options.template, options.data

# create plain-text version from html
if settings.plainText
try
opts.text = htmlToText.fromString opts.html
catch ex
Utils.Logger.error "Could not make plain-text version from html: " + ex.message

catch ex
Utils.Logger.error 'Could not render email before sending: ' + ex.message, TAG
return false
Expand Down
6 changes: 5 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ var where = 'server';
Package.describe({
name: 'lookback:emails',
summary: 'Send HTML emails with server side Blaze templates. Preview and debug in the browser.',
version: '0.5.1',
version: '0.6.0',
git: 'https://github.com/lookback/meteor-emails.git'
});

Npm.depends({
"html-to-text": "1.3.0"
});

Package.onUse(function(api) {

api.versionsFrom('1.0.4');
Expand Down