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
1 Introduction. Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.
Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.
Mail will automatically Base64 encode an attachment. If you want something different, encode your content and pass in the encoded content and encoding in a Hash to the attachments method. Pass the file name and specify headers and content and Action Mailer and Mail will use the settings you pass in.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With