Send an email manually of a specific page in rails app

有些话、适合烂在心里 提交于 2019-12-12 09:26:52

问题


I have a basic application that gathers savings data for clients each quarter. There is a view that shows this data for each client compared to other client data with charts and graphs. I'm looking for an easy way to implement a button (or something) that allows me to manually send that view to the client in an html email at my discretion. I have only found tutorials showing how to send emails upon registration or confirmation type emails.


回答1:


# app/mailers/user_mailer.rb
class UserMailer < ActionMailer
  def report
    @things = Thing.report_stuff
    mail :to => 'boss@example.com', :from => 'you@example.com', 
      :subject => 'that report you want'
  end
end

# app/views/user_mailer/report.html.erb
<h1>Report</h1>
<% @things.each do |thing| %>
  <%= thing.name %>
<% end %> 

# app/controllers/reports_controller.rb
def create
  UserMailer.report.deliver
  flash[:notice] = 'report sent!'
  redirect_to root_path # or wherever
end

# in a view
<% form_tag(reports_path, :method => :post) do %>
  <% submit_tag 'send report email' %>
<% end %>


来源:https://stackoverflow.com/questions/5545574/send-an-email-manually-of-a-specific-page-in-rails-app

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