classUserMailer < ApplicationMailer defpassword_reset(user) @user =user mail to: user.email , subject:"Password reset" end end
app/mailers/application_mailler.rb
1 2 3 4
classApplicationMailer < ActionMailer::Base default from: user_email layout 'mailer' end
app/views/user_mailer/password_reset.html.erb
1 2 3 4 5 6 7 8 9 10 11 12
<h1>Password reset</h1> <p> To reset your password click the link below: </p> <%= link_to "Reset Password",edit_password_reset_url(@user.reset_token, email:@user.email) %> <p>This link will expire in two hours.</p> <p> If you did not request your password to be reset, please ignore this email and your password will stay as it is. </p>
app/views/user_mailer/password_reset.text.erb
1 2 3 4
To reset your password click the link below: <%= edit_password_reset_url(@user.reset_token,email:@user.email) %> This link will expire in two hours. If you did not request your password to be reset, please ignore this email and your password will stay as it is.
4.调用邮件方法
app/models/user.rb
1 2 3 4
#发送密码重设邮件 defsend_password_reset_email UserMailer.password_reset(self).deliver_now end