ruby on rails - RubyOnbRails - Render mail to string -
i have rubyonrails 3.2.x application sends out mails using actionmailer.
the code goes this:
class mymailer < actionmailer::base def sendout mail(:to->"someone@somewhere.com", :from ........... end end instead of sending out email, want rendered string plan process differently
ps: in specific case want pass string node.js server actual sending of mail, using rubyonrails handle multi language support , number formatting (yes have multiple templates different languages support).
since ruby won't doing email sending, there's no need use mailer.
ideally generate json string representation of email like:
# @ top of file require 'json' # in method json_string = { :to => "email@example.com", :from =>"sender@example.com", :body => "this body" }.to_json then post string node.js server (for example) controller or whatever calling mailer.
however, since want render email using templates pull in db fields , use i18n functionality of rails, use mailer render result string follows:
mail(to: "mail@example.com") |format| format.html string = render_to_string("your_template") call_node_js(string) end end
Comments
Post a Comment