johncant / mailman-rails

Integrate Mailman with Rails
MIT License
16 stars 6 forks source link

Run Mailman via cron #6

Open pecha7x opened 10 years ago

pecha7x commented 10 years ago

Hi, please help me. I want getting emails from many emails addresess. I havn't yet found solutions besides busting these addresses and run script for each address. All addresses basic on one pop3 server. It's possible? I try next-

rake task-


namespace :jobs do
  task :mailman => :environment do
    puts 'Starting Mailman Server'
    Tenant.find_each do |tenant|
      `script/mailman_server #{tenant.system_email} #{tenant.system_pwd}`
    end
  end
end

script-
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"
Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.pop3 = {
    server: 'dev.ddd.de',
    username: "#{ARGV[0]}",
    password: "#{ARGV[1]}"
}
Mailman::Application.run do
  default do
    puts "EMAIL LISTENER INCOMING MESSAGE ----> #{message}"
    exit
  end
end

But script "stoped" on first email. ie there is no incoming messages and the script continues to hang at this address. How I can exit from "processing" and continie? Please any comment...

johncant commented 10 years ago

I'm not really sure to be honest, since I haven't used ruby mailman with POP3. Could it be waiting to receive more mail from the POP3 server?

mailman-rails bundles rake tasks for running a daemon, which should watch or poll for new mail. If you use the mailman DSL within Mailman::Rails.receive, then, you could use the rake tasks that are bundled with this gem to run the mailbox watching process as a daemon.

Unfortunately, A limitation of mailman-rails is that it only supports one Mailman::Application - a simplification rather than a deliberate limitation. IMHO, you probably want one process and several threads watching the various tenants mailboxes. I'd be more than happy for you to add support for multiple Mailman::Applications to this gem.

Also, are you sure you're even using the gem and not https://github.com/titanous/mailman ? mailman-rails is a convenience gem whereas mailman does all the heavy lifting.