0

我有以下简单的脚本,它检查电子邮件帐户,如果有新邮件,它会转发电子邮件并发送短信。当脚本在没有Process.daemon. 添加后,电子邮件帐户收到电子邮件,没有任何反应(没有转发,也没有发送 SMS)并且控制台中没有错误消息。有什么建议么?

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

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

Mailman.config.poll_interval = 60

Mailman::Application.run do  
  default do
    begin
      Ticket.receive_mail(message)
      MailForwarder.forwarded_email(message).deliver
      @account_sid = 'xxxxxxxxxxx'
      @auth_token = 'xxxxxxxxxx'
      @client = Twilio::REST::Client.new(@account_sid, @auth_token)
      @account = @client.account
      @sms = @account.sms.messages.create(
        :from => '+1111111111',
        :to => '+122222222',
        :body => message.subject
      )
      puts @sms
      puts "#{message.subject}"
    rescue Exception => e
      Mailman.logger.error "Exception occurred whle receiving message:\n#{message}"
      Mailman.logger.error [e, *e.backtrace].join("\n")
    end
  end
  Process.daemon
end
4

1 回答 1

1

我相信您需要在启动 mailman 应用程序之前将您的脚本设置为守护进程。我做了一些测试,如果我在调用 Mailman::Application.run 之前调用 Process.daemon 它工作正常,但如果我把它放在你有它的地方它就不起作用。

所以我把它当作:

....

Mailman.config.poll_interval = 15

Process.daemon

Mailman::Application.run do

 default do


 end

end
于 2013-07-25T17:01:28.110 回答