How to render rails mailer views in Mailgun HTTP API

夙愿已清 提交于 2019-11-30 13:28:08
Yosep Kim

How about using the render_to_string method? I believe you want to dynamically generate the view content. Reading up the view template by opening up the file would not run any Ruby code in it.

    class MailgunMails < ActionMailer::Base

        def send_complex_message
          data = Multimap.new
          data[:from] = "Excited User <postmasters@#{@@domain}>"
          data[:to] = "alice@example.com"
          data[:subject] = "Hello"
          html_output = render_to_string template: "mailgun_mails/send_complex_message"
          data[:html] = html_output.to_str
          response = RestClient.post "https://api:#{@@private_key}"\
          "@api.mailgun.net/v2/#{@@domain}/messages", data

          response = JSON.parse(response)

        end

     end  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!