I'm putting together an email scheduler/sender in a Ruby on Rails application. I am using the Bunny gem for creating a messaging queue, and I have a Rufus scheduler that periodically puts messages into the queue. I am using a Sneakers rake task to pull in messages from the queue whenever they are added. I start the Sneakers worker from the command line like so:
WORKERS=Processor rake sneakers:run
The code reaches the mail() function and then quits, the email template isn't even being generated. I have working email code in my normal application and I transferred the configurations over to the rake task, so I know my configurations are correct.
app/workers/processor.rb
require 'sneakers'
require 'json'
require 'action_mailer'
class Processor
include Sneakers::Worker
from_queue :email_queue,
:env => 'development',
:ack => true
Sneakers.configure {}
Sneakers.logger.level = Logger::ERROR
Sneakers::Worker.configure_logger(Logger.new('/dev/null'))
def work(msg)
string = msg.force_encoding("ISO-8859-1")
hash = JSON.parse(string)
ack!
UserMailer.test_email(hash).deliver
end
end
app/mailer/user_mailer.rb
require 'action_mailer'
require 'fog'
require 'rubygems'
class UserMailer < ActionMailer::Base
def test_email(hash)
@order = hash["order"]
@currentUser = hash["user"]
@staffCompany = hash["company"]
mail(to: "[email protected]", from: "[email protected]", subject: 'Action Mailer')
end
end
app/views/user_mailer/test_email.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<div class="PlainText">
Some text goes here
</div>
</body>
</html>
config/environments/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'gmail account',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true}
Any help would be greatly appreciated!
edit 1: Moved the template to the correct location, but the template still isn't rendering and the email isn't being sent out.