How to get the email message body with ActionMailer - ruby-on-rails

I am sending an standard email with Rails like this
#mail = mail(to: registration.user.email, subject: "Registration Confirmation: #{#site.name}")
Now i need to get the message body (or html in this case) from the email. I tried the following but it does not work since it returns not the rendered email but rather the template (including ERB and Haml).
#mail.body
#mail.body.raw_source
#mail.body.encoded
It seems surprisingly difficult to do this. I need the result that a persons sees when receiving the email.
Update
The ERB and Haml i saw was an HTML comment, that's why in the logs it looked like it logged ERB instead of a rendered tempalte. So #mail.body.encoded works fine.

I tried the accepted answer but it is showing the HEADER along with HTML. To get the HTML tags only I've used below code:
#mail.html_part.body.decoded

How about #mail.body.encoded (which should give you the result for which you seek)?

Related

Mailboxer html formattting

How can I allow Mailboxer gem to send HTML formatted messages?
For example, I want the first message user A sends to user B to be pre-formatted with certain text and HTML tags. Currently any kind of markup is escaped..
EDIT: My question is basically how can I "patch" the send_message functionality? Or create a new send_message2 that behaves the way I want?

Using Render in my .rb file

Hi I have some html in a file called (a partial):
_quotemail.html.erb
I Am sending an email to a user and I want to put this html in the email. I am using mailgun.
I can define my email body like so:
body = "text to go in email"
which works great but I want to instead include the HTML I have in my quotemail partial.
Whats the best way to do this?

How to make a Rails 3 contact form send the contents of the form

I feel like an idiot here. Based on multiple tutorials I setup a basic contact form. The mail sends fine and all. But the contents of the email aren't there. The subject works fine.
Processing by PagesController#create_message as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ernukxaM9arPJwd8gmuxa/poc4FMh+s6ItsXAMW7BcE=", "message"=>{"name"=>"TJ", "email"=>"tj#tjsherrill.com", "body"=>"Test after file name change"}, "commit"=>""}
this is the console output.
My code: https://gist.github.com/anonymous/5924775
there is just no content in the email...
According to your gist you have the email view as contact_us_mailer.html.erb. It should be app/views/contact_us_mailer/new_message.html.erb

Rails3 - email template

I am fetching email content from database and storing it in variable and passsing it to email template.
i.e:
#email_content = Email.find(1)
#email_content = #email_content.content
My content is like this: "hi, how are you doing, thanks". With html <br/> tags in between the content.
Problem is, I'm getting the mail as plain text, the html tags are not working.
Could someone help me solve this?
In your view file you need to put this
<%= #email_content.html_safe %>

How to put a button to action in an email template in RoR

My application sends notification emails to users, I would like to put a button in the email that links to a certain action in a controller?
When I put regular html code (like <input type="button" .... />, I get it in the received email as string, that is, I find the html code in the email) How can I skip this trap?
It's not a perfect idea to send messages as html. By default I turn off html in my email account.
Look this screencast for a beginning: http://railscasts.com/episodes/206-action-mailer-in-rails-3. You just need to specify different view formats: html or text for plain text. But in any case it will rely on reciever email settings which format will be choosen.

Resources