まず、必要なアクションを書き込むためのメーラーを生成します。
rails g mailer UserMailer
次に、app / mailers/user_mailer.rbファイルにあります
class UserMailer < ActionMailer::Base
default from: 'notifications@example.com'
def order_confirmation(user, order)
@user = user
@order = order
mail(to: user.email, subject: 'Order has been received')
end
end
メールの表示内容は次のようになりますapp/views/user_mailer/order_confirmation.html.erb
Hi <%= @user.name %>
You have successfully placed an order with us.
Please find the details of order....
#.............
次に、注文を作成するコントローラーアクションで、注文を作成した後に次の行を入力してメールを送信します
UserMailer.order_confirmation(user, order).deliver
詳細については、アクションメーラーのチュートリアルを参照してください。