我有一个 Rails 应用程序,它使用 mailman gem(链接)来收集入站 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