0

我有带有下一个代码的 UserMailer 类:

用户.rb:

 devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

  -----------------

 class UserMailer < ActionMailer::Base

 default :from => "denys.medynskyi@gmail.com"

 def password_reset(user, password)
   @user = user
   @password = password
  mail(:to => user.email,
     :subject => 'Password Reset Notification')
  end

  def congrats_email(user)
    mail(to: user.email, subject: "Welcome Message")
 end

 end

setup_mail.rb:

    ActionMailer::Base.smtp_settings = {
   :address              => "smtp.gmail.com",
   :port                 => 587,
   :domain               => "gmail.com",
   :user_name            => "denys.medynskyi",
   :password             => "********",
   :authentication       => "plain",
   :enable_starttls_auto => true
    }

并来自 devise.rb:

Devise.setup do |config|
  # ==> Mailer Configuration
  config.mailer_sender = "UserMailer"
end

在忘记密码提交后,我转到某个页面,但它没有显示任何通知,并且没有发送电子邮件。

我做错了什么?

4

1 回答 1

0

I'm not 100% sure this is the cause of any or all of your problems, but if you're trying to work with Devise, overriding some of the default mailer behavior but not all of it, you should inherit from Devise::Mailer rather than ActionMailer::Base.

So

class UserMailer < Devise::Mailer

Edit: The method that Devise calls in Devise::Mailer to render the password reset mail template is reset_password_instructions. So your method isn't even overwriting that. Also, the way Devise works, it's the resource that eventually calls the method that sends the instructions e-mail. The job of the reset_password_instructions method is just to generate the e-mail from the view template. So it looks to me like the code you've got above isn't really working with the normal Devise flow. What calls password_reset in your app?

于 2012-10-18T15:24:41.783 回答