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

Commit dae8895

Browse files
committed
Merge pull request #42 from satyavh/master
Feature: automatically create plain text version from html template to reduce spam score
2 parents 8030694 + 3909b1e commit dae8895

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Usually, building HTML emails yourself is tedious. On top of that, add the need
1717
6. [Paths](#paths)
1818
7. [Sample file structure](#sample-file-structure)
1919
8. [Logging](#logging)
20+
9. [Plain-text](#plain-text)
2021
6. [Version history](#version-history)
2122
7. [Contributing](#contributing)
2223

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

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

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

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

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

446+
### Plain-text
447+
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()`:
448+
449+
```coffeescript
450+
Mailer.init(
451+
settings:
452+
plainText: false
453+
)
454+
```
455+
442456
## Version history
443457

458+
- `0.6.0` - Automatically create and include plain-text email version from your HTML templates
444459
- `0.5.1` - Remove need for setting the `BUNDLE_PATH` environment variable ([#39](https://github.com/lookback/meteor-emails/pull/39)).
445460
- `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)).
446461
- `0.4.6` - Fix paths on Windows in development mode.

emails.coffee

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
TAG = 'mailer'
99

10+
# used to make plain-text version from html version
11+
htmlToText = Npm.require 'html-to-text'
12+
1013
# ## Setup
1114

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

3135
juiceOpts:
3236
preserveMediaQueries: true
@@ -226,6 +230,14 @@ MailerClass = (options) ->
226230
# Render HTML with optional data context.
227231
try
228232
opts.html = render options.template, options.data
233+
234+
# create plain-text version from html
235+
if settings.plainText
236+
try
237+
opts.text = htmlToText.fromString opts.html
238+
catch ex
239+
Utils.Logger.error "Could not make plain-text version from html: " + ex.message
240+
229241
catch ex
230242
Utils.Logger.error 'Could not render email before sending: ' + ex.message, TAG
231243
return false

package.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ var where = 'server';
33
Package.describe({
44
name: 'lookback:emails',
55
summary: 'Send HTML emails with server side Blaze templates. Preview and debug in the browser.',
6-
version: '0.5.1',
6+
version: '0.6.0',
77
git: 'https://github.com/lookback/meteor-emails.git'
88
});
99

10+
Npm.depends({
11+
"html-to-text": "1.3.0"
12+
});
13+
1014
Package.onUse(function(api) {
1115

1216
api.versionsFrom('1.0.4');

0 commit comments

Comments
 (0)