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

Closed
greyblake opened this Issue Apr 10, 2012 · 2 comments

Projects

None yet

2 participants

@greyblake
Contributor

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
Member

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

@greyblake
Contributor

Hoh.. You are right. Thanks!

@greyblake greyblake closed this Apr 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment