Rails convert an html email to a text email

Given an html email message, is there a way to convert that to a text version? I'm doing email ingestion and notice that some times an email doesn't include a text version, especially with blackberry devices.

thanks

Answers


Perhaps I'm missing something, but couldn't you just take the HTML message and run ActionView::Helpers::SanitizeHelper#strip_tags over it?

http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags


HTML to Text is one of the features provided by the Premailer gem.

premailer = Premailer.new('http://example.com/html_email.html')
premailer.to_plain_text

In case you don't want to use it because it does a lot, you can look at the code for how it does it here


I know this post is old, but it comes up high in Google for "convert html to text". The following may meet your needs:

The author says:

Ruby convert HTML to formatted text — Chip’s Tips for Developers. When you want to have your whitespace and feed it, too.

http://www.chipstips.com/?p=610


Refer the following link http://edgeguides.rubyonrails.org/action_mailer_basics.html

Action mailer provides options for sending a html or text emails.......


Need Your Help

Make UIImagePickerController (Camera view) only show a certain # of pixels

iphone objective-c ios uiimage uiimagepickercontroller

How do I make UIImagePickerController (Camera view) only show a certain # of pixels (400 * 400 perhaps).

PowerShell script not properly e-mailing Excel report file when ran automatically in the scheduler

windows excel powershell scheduled-tasks task

When I run the PowerSheel script manually - through a .bat file that executes it with the PowerShell interpreter - it correctly executes an SQL query and creates an Excel file and e-mails it.