class NotificationMailer < Prism::Mailer::Base self.template_roots = [File.join(APP_ROOT, 'app', 'views', 'mailers')] default from: 'blog@prism.example' def new_post(post_id) @post = Post.find(post_id) @post_url = "/posts/#{@post.to_param}" mail(to: 'editors@prism.example', subject: "New post: #{@post.title}") end def welcome(user_id) @user = User.find(user_id) mail(to: @user.email, subject: 'Welcome to Prism Blog') end # `token` is generated by the caller (User#generate_token_for(:password_reset), # see PasswordResetsController#create) rather than here - keeps this # mailer, like the others, a pure "given the data, render+send" step with # no signing concerns of its own. def password_reset(user_id, token) @user = User.find(user_id) @reset_url = url_for(:edit_password_reset, token: token) mail(to: @user.email, subject: 'Reset your Prism Blog password') end # `token` is generated by the caller, same reasoning as password_reset # above - either User's own after_commit(on: :create) at signup time, or # EmailConfirmationsController#create for a resend. def confirmation_instructions(user_id, token) @user = User.find(user_id) @confirmation_url = url_for(:email_confirmation, token: token) mail(to: @user.email, subject: 'Confirm your Prism Blog email address') end end