No release in over 3 years
Low commit activity in last 3 years
Automatically add plain text parts into HTML emails sent by ActionMailer.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

actionmailer-html2text Build Status

actionmailer-html2text automatically adds plain text parts to HTML emails sent by ActionMailer, using html2text, and inspired by this blog post.

For example:

<html>
<title>Ignored Title</title>
<body>
  <h1>Hello, World!</h1>

  <p>This is some e-mail content.
  Even though it has whitespace and newlines, the e-mail converter
  will handle it correctly.

  <p>Even mismatched tags.</p>

  <div>A div</div>
  <div>Another div</div>
  <div>A div<div>within a div</div></div>

  <a href="http://foo.com">A link</a>

</body>
</html>

Will be converted into:

Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.
A div
Another div
A div
within a div
[A link](http://foo.com)

Notes

  1. Any existing text/plain parts will not be overwritten, so you can still create custom text parts with template.text.erb and template.html.erb

  2. Any HTML email emails processed will become multipart in order to add the text/plain part.

  3. Issues and pull requests welcome!

Installing

Add the gem into your Gemfile and run bundle install:

gem 'actionmailer-html2text'

You can now enable automatic text parts on just a single mailer:

class WelcomeMailer < ApplicationMailer
  include ActionMailer::Html2Text                # Just add this

  def welcome_email(to)
    mail(to: to, subject: "Subject")
  end
end

Or you can add it to all of your mailers:

class ApplicationMailer < ActionMailer::Base
  include ActionMailer::Html2Text                # Just add this

  default from: "from@example.com"
  layout 'mailer'
end

Tests

bundle install
rspec

License

actionmailer-html2text is licensed under MIT.

Other versions

  1. openclerk/emails is a PHP e-mail framework that automatically generates text multiparts