Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7044645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:26:04+00:00 2026-05-28T02:26:04+00:00

After switching my Rails 2.3 app from MRI Ruby 1.8.7 to JRuby 1.6.5, the

  • 0

After switching my Rails 2.3 app from MRI Ruby 1.8.7 to JRuby 1.6.5, the app is no longer able to send mail. I’m using ActionMailer like this:

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(...)

That’s probably irrelevant, since this all works under MRI Ruby 1.8.7.

The Rails app is configured to use sendmail in config/environments/production.rb:

config.action_mailer.delivery_method = :sendmail

What’s more interesting are the sendmail logs (/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=<201201051438.q05EcnCr024755@my.example.org>, relay=edwarda@localhost
Jan  5 09:38:49 my sm-mta[24757]: q05Ecn02024757: from=<edwarda@my.example.org>, size=516, class=0, nrcpts=1, msgid=<201201051438.q05EcnCr024755@my.example.org>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jan  5 09:38:49 my sendmail[24755]: q05EcnCr024755: to=me@example.com, 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=<me@example.com>, ctladdr=<edwarda@my.example.org> (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, relay=edwarda@localhost

Note that the nrcpts (number of recipients) is 0 when I’m running JRuby and 1 when running 1.8.7.

I’m using the exact same code and gems, except I’m using these gems in addition for 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'

In case it’s useful, this is my Gemfile.lock.

There is no interesting or unusual output in my Rails logs; only the usual success messages.

edit: I cannot reproduce this problem on my development (OSX) machine.

Any thoughts on why the recipients might be getting lost or how I might troubleshoot this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:26:04+00:00Added an answer on May 28, 2026 at 2:26 am

    This is related to a JRuby bug: http://jira.codehaus.org/browse/JRUBY-6162

    Apparently IO.popen is closing prematurely when it tries to execute the sendmail command. Until this is fixed upstream, this monkey patch can be included in an initializer to work around the problem:

    Rails 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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been considering switching from using PHP to Ruby on Rails for my web
After switching from RVM to system ruby I keep getting this error. It doesn't
After switching from firefox testing to internet explorer testing, some elements couldn't be found
Using Ruby 1.8.6 / Rails 2.3.2 I am noticing that any method called on
Background: I am using the RailsInstaller 2 package from Engine Yard, which means Ruby
I'm experiencing some different behavior after switching from ASP.NET MVC 1.0 to ASP.NET MVC
After switching to Rails 3, I noticed that I have to reboot my server
After switching from 64-bit to 32-bit platform (both of them are CentOS) I get
After switching from C++ to C++ w/boost, do you think your OOD skills improved?
After switching to window 7, I can no longer use the external debugger with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.