Given an html开发者_如何学Python 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
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
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
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.......
精彩评论