1

I want to resend an activation email to users if they do not activate it in 48 hours. I used whenever gem but it is not sending the email. even if action mailer works fine and sends an email when a user signs up schedule.rb

 set :environment, :development
      every 1.minutes do
        runner "user.resend_account_activation"
    end

user_mailer.rb

def resend_account_activation
    @user = User.where('activated = ?',false && 'activated_at < ?',48.hours.ago)

    mail to: @user.email, subject: "You forgot to activate"
  end

user.rb

 def resend_account_activation
      # @outdated_users = User.where('activated_at < ?',30.seconds.ago)
      UserMailer.resend_account_activation.deliver_now!

  end

In my cmd

# Begin Whenever generated tasks for: store
* * * * * /bin/bash -l -c 'cd /mnt/c/Sites/testApp && bin/rails runner -e production '\''user.resend_account_activation'\'''

# End Whenever generated tasks for: store
Nejweti
  • 113
  • 2
  • 11

1 Answers1

0

I think it should not be user.resend_account_activation

It will be something like this

user.rb

def self.resend_account_activation_to_users
  User.where('activated = ? AND activated_at < ?', false ,48.hours.ago).each do |user|
    UserMailer.resend_account_activation(user.id).deliver_now!
  end
end

Note: I have changed the 48 hrs query. pls check before execution

user_mailer.rb

def resend_account_activation(user_id)
  @user = User.find(user_id)
  mail to: @user.email, subject: "You forgot to activate"
end

runner "User.resend_account_activation" # Note: changed user => User