如何制作一个像'script / mailman_server'适用于Rails应用程序中的多个用户

时间:2013-04-19 21:17:00

标签: ruby-on-rails ruby-on-rails-3 mailman mailman-gem

我有一个Rails应用程序,它使用mailman gem(link)来收集入站pop3邮件并使用它们进行操作。这一切都很好,但现在我希望有多个用户注册并从他们的pop3配置接收邮件。 Mailman在'script / mailman_server'中运行,我不熟悉如何使脚本(运行自己的进程)为多个用户工作。任何人都可以启发我这个主题或链接到涉及这个主题的资源吗?

这是我现在的代码

# script/mailman_server

#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"

Mailman.config.pop3 = {
  :username => 'some_name@some_email.com',
  :password => 'some_password',
  :server   => 'pop.gmail.com',
  :port     => 995,
  :ssl      => true
}

Mailman::Application.run do
  default do
    Email.receive_mail(message)
  end
end


# app/models/email.rb

class Email
  include Mongoid::Document
  include Mongoid::Timestamps

  field :from, type: String
  field :subject, type: String
  field :body, type: String

  belongs_to :customer, :inverse_of => :emails

  def self.receive_mail(message)
    email = Email.create!(subject: message.subject, body: message.body.decoded, from: message.from.first)
  end
end

0 个答案:

没有答案