2012-01-05 15 views
1

Rails 2.3アプリをMRI Ruby 1.8.7からJRuby 1.6.5に切り替えると、アプリはメールを送信できなくなります。私はActionMailerを次のように使用しています。RailsアプリはJRubyの下でメールを送信しません

class MessageMailer < ActionMailer::Base 
    def message(msg, recipient, reply_to_email=nil) 
    template = (msg.message_type.nil?) ? "default" : msg.message_type.name.downcase.gsub(' ', '_') 

    recipients recipient 
    subject msg.subject 
    from (msg.sender.nil? or msg.sender.email.blank?) ? "\"no-reply\" <#{SYSTEM_EMAIL_ADDRESS}>" : msg.sender.email 
    content_type "text/html" 
    body render_message(template, :message => msg) 
    reply_to reply_to_email || ((msg.sender.nil? or msg.sender.email.blank?) ? "\"no-reply\" <#{SYSTEM_EMAIL_ADDRESS}>" : msg.sender.email) 
    end 

    ... 
end 

MessageMailer.deliver_message(...) 

これはMRI Ruby 1.8.7で動作するため、これはおそらく無関係です。

のRailsアプリが設定/環境/ production.rbでのsendmailを使用するように設定されています。もっと面白い何

config.action_mailer.delivery_method = :sendmail 

あるsendmailのログ(/var/log/mail.log):

# Sending mail under MRI Ruby 1.8.7 
Jan 5 09:38:49 my sendmail[24755]: q05EcnCr024755: from=edwarda, size=310, class=0, nrcpts=1, msgid=<[email protected]>, [email protected] 
Jan 5 09:38:49 my sm-mta[24757]: q05Ecn02024757: from=<[email protected]>, size=516, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1] 
Jan 5 09:38:49 my sendmail[24755]: q05EcnCr024755: [email protected], ctladdr=edwarda (1011/1012), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30310, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (q05Ecn02024757 Message accepted for delivery) 
Jan 5 09:38:49 my sm-mta[24759]: STARTTLS=client, relay=aspmx.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=RC4-SHA, bits=128/128 
Jan 5 09:38:49 my sm-mta[24759]: q05Ecn02024757: to=<[email protected]>, ctladdr=<[email protected]> (1011/1012), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120516, relay=aspmx.l.google.com. [74.125.45.27], dsn=2.0.0, stat=Sent (OK 1325774329 o43si18661797yhk.140) 

# Sending mail under JRuby 1.6.5 
Jan 5 11:10:26 my sendmail[7623]: q05GAQkH007623: from=edwarda, size=199, class=0, nrcpts=0, [email protected] 

JRubyを実行しているときはnrcpts(受信者の数)は0で、1.8.7を実行しているときは1であることに注意してください。

私はJRubyのために加えて、これらの宝石を使用している以外、私は、まったく同じコードと宝石を使用しています:

gem 'activerecord-jdbc-adapter', '<= 1.2.0', :require => false 
gem 'activerecord-jdbcpostgresql-adapter', '<= 1.2.0', :require => 'jdbc_adapter' 
gem 'ffi-ncurses' 
gem 'jruby-openssl' 
gem 'torquebox', '2.0.0.beta1', :platforms => 'jruby' 
gem 'torquebox-rake-support', :platforms => 'jruby' 
gem 'torquebox-capistrano-support', '2.0.0.beta1' 

場合、それは便利です、これは私のGemfile.lockです。

私のRailsログには興味深い、または珍しい出力はありません。通常の成功メッセージのみ。

編集:私の開発(OSX)マシンでこの問題を再現することはできません。

なぜ受信者が迷子になっているのか、またはこれをトラブルシューティングする方法についての考えはありますか?

+0

は1.9モードで動作しているJRubyのです?どのバージョンのレール? –

+0

JRubyは1.8モードで動作しています。 Rails 2.3.14 –

答えて

3

これは、JRubyのバグに関連している:それはsendmailコマンドを実行しようとしたときhttp://jira.codehaus.org/browse/JRUBY-6162

どうやらIO.popenが早まって閉じています。この上流修正されるまで、この猿のパッチが問題を回避するには初期化子に含めることができます。

レール2:

module ActionMailer 
    class Base 
    def perform_delivery_sendmail(mail) 
     sendmail_args = sendmail_settings[:arguments] 
     sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path'] 

     IO.popen("#{sendmail_settings[:location]} #{sendmail_args}", "r+") do |f| #r+ geht, w+ geht nicht richtig, bzw. nur manchmal 
     f.puts mail.encoded.gsub(/\r/, '') 
     f.close_write 
     sleep 1 # <---- added this line in order to give sendmail some time to process 
     end 
    end 
    end 
end 

のRails 3:

module Mail 
    class Sendmail 

    def initialize(values) 
     self.settings = { :location  => '/usr/sbin/sendmail', 
         :arguments  => '-i -t' }.merge(values) 
    end 

    attr_accessor :settings 

    def deliver!(mail) 
     envelope_from = mail.return_path || mail.sender || mail.from_addrs.first 
     return_path = "-f \"#{envelope_from.to_s.shellescape}\"" if envelope_from 

     arguments = [settings[:arguments], return_path].compact.join(" ") 

     Sendmail.call(settings[:location], arguments, mail.destinations.collect(&:shellescape).join(" "), mail) 
    end 

    def Sendmail.call(path, arguments, destinations, mail) 
     IO.popen("#{path} #{arguments} #{destinations}", "r+") do |io| 
     io.puts mail.encoded.to_lf 
     io.close_write # <------ changed this from flush to close_write 
     sleep 1 # <-------- added this line 
     end 
    end 
    end 
end 
0

ほとんどの場合、古いバージョンでは、受信者ヘッダーを含まない "sendmail -t"にメッセージが渡された可能性があります。 -tは、sendmailがそれらのヘッダを使ってメールがどこに行くかを知るようにします。そうしなければ、from =行のログにnrcpts = 0が得られます。

+0

古いバージョンのものは何ですか? –

+0

メールの送信に使用している古いバージョンのモジュールです。 –

+0

それはActionMailerではありませんか? –

関連する問題