I want to use ActionMailer in my rake task in order to send emails to people at a particular time.
I have written a mailer class in app/mailers folder like this:
class AlertsMailer < ActionMailer::Base
default from: '[email protected]'
def mail_alert(email_addresses, subject, url)
@url = '#{url}'
mail(to: email_addresses, subject: 'Alert') do |format|
format.html { render '/alerts/list' }
end
end
end
Then I included the following line in my rake task:
AlertsMailer.mail_alert(email_addresses, subject)
When I try to run the rake task:
rake update_db
I get the following error:
uninitialized constant AlertsMailer
I think I have to somehow load the mailer class in my rake task, but I don't have any idea how to do that.
Please help.