mardi 19 janvier 2021

Cron and Actionmailer in rails. Unable to use wherever gem

I am trying to schedule a mail to be sent at a particular time every day. I have set up the action mailer in my project. It is working. Now I am trying to use cron and whenever gem.

This is my controller.

def create
    @user = User.new(user_params)

    respond_to do |format|
      if @user.save
        ExampleMailer.sample_email(@user).deliver

        format.html { redirect_to @user, notice: 'User was successfully created.' }
        format.json { render :show, status: :created, location: @user }
      else
        format.html { render :new }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

This is my mailer

class ExampleMailer < ApplicationMailer
    default from: "from@example.com"
    def sample_email(user)
        @user = user
        mail(to: @user.email, subject: 'This mail is sent by suhasmv')
      end
    
end

This is schedule.rb

set :environment, "development"

every 3.minutes do
    rake 'send_digest_email'
end

this is my task


desc 'send digest email'
task send_digest_email: :environment do
  # ... set options if any
  ExampleMailer.sample_email(User.last).deliver!

end

I tried to create a tasks. But couldn't set it up.

Could anyone let me know.

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire