Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

ActionMailer: format.text doesn't build email text_part without html_part. #5801

Closed
greyblake opened this Issue · 2 comments

2 participants

@greyblake

format.text doesn't build text part of email when html part is not specified.

Rails 3.2.2


# When everything work
class TestMailer < ActionMailer::Base
  default :from => "from@example.com", :to => "to@example.com"

  def hello
    mail do |format|
      format.text { render :text => "Hello!" }
      format.html { render :text => "<h1>Hello!</h1>" }
    end
  end

end

hello_email = TestMailer.hello
hello_email.text_part.body.to_s # => "Hello!"
hello_email.html_part.body.to_s # => "<h1>Hello!</h1>"


##################################################################################


# When nothing works!!!
class TestMailer < ActionMailer::Base
  default :from => "from@example.com", :to => "to@example.com"

  def hello
    mail do |format|
      format.text { render :text => "Hello!" }
      # We just commented it out
      # format.html { render :text => "<h1>Hello!</h1>" }
    end
  end

end

hello_email = TestMailer.hello
hello_email.html_part # => nil, it's OK
hello_email.text_part # => nil, WTF?

@pixeltrix
Owner

At a guess it's probably because the latter isn't a multipart email - what do you get for hello_email.body?

@greyblake

Hoh.. You are right. Thanks!

@greyblake greyblake closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.