I’m starting to play with Slantwise.com’s Fetcher to process emails via
a Ruby script.
Here’s the basic code lifted from their plugin:
class MailFetcherDaemon < Daemon::Base
@config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
@config = @config[RAILS_ENV].to_options
@sleep_time = @config.delete(:sleep_time) || 10
def self.start
puts "Starting MailFetcherDaemon"
# Add your own receiver object below
@fetcher = Fetcher.create({:receiver => nil}.merge(@config))
loop do
puts "checking mail"
@fetcher.fetch
sleep(@sleep_time)
end
end
def self.stop
puts "Stopping MailFetcherDaemon"
end
end
MailFetcherDaemon.daemonize
my question is about receiver. According to the docs, such as they are,
receiver is a class that is subclassed from ActiveMailer::Base. it needs
to have a ‘receive’ method. Fine. I’ve created a class called Recipient,
it lives in app>models, and the mail.yml file uses it to find out the
name of the class that is the receiver. When I start the daemon, it
seems to start without complaint.
Here’s recipient.rb:
class Recipient < ActionMailer::Base
def receive(msg)
"got that"
end
end
When running, the loop, on finding emails in the designated account is
supposed to pass them one at a time to the receive method, and then
delete the message.
The messages get deleted, so the daemon is running, and the login/pass
to the account are in the mail.yml file, so that’s getting read. But the
puts “got that” never appears in the console when I run it there on
localhost.
What am I doing wrong???
Driving me nuts.