-
-
Save develop7/3634e1fcc48822765d1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Automatically generates the plain-text version of emails from the html | |
# template using premailer. | |
class SmartMailer < ActionMailer::Base | |
protected | |
def collect_responses(headers) | |
responses = super(headers) | |
if responses.none? { |r| r[:content_type] == 'text/plain' } | |
html = responses.find { |r| r[:content_type] == 'text/html' } | |
if html | |
premail = Premailer.new(html[:body], with_html_string: true) | |
responses << { content_type: 'text/plain', body: premail.to_plain_text } | |
end | |
end | |
responses | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment