Rails 3 - Developer / ActionMailer / RUBY -SMTP causing segmentation fault

Okay - I'm here on my head. I use:

  - ruby-1.9.3-p0
  - rails-3.1.3
  - mail-2.3.0
  - devise-1.5.3


Trying to enable Devise option :confirmable

and start smtp services in my application. As soon as I add /config/initializers/setup_mail.rb

, add the required columns in my DB and an attribute :confirmable

to my model User

, I get a segmentation error. This happens immediately after user registration. Devise

trying to send a confirmation email, causing the ruby โ€‹โ€‹smtp library to crash with the following:

... lib/ruby/1.9.1/net/smtp.rb:583: [BUG] Segmentation fault


Last entry in log/development.log


Rendered devise/mailer/confirmation_instructions.html.erb (1.2ms)


My /config/initializers/setup_mail.rb


ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "mydomain.com",
  :user_name            => "support@mydomain.com",
  :password             => "???????",
  :authentication       => "plain",
  :enable_starttls_auto => true
ActionMailer::Base.default_url_options[:host] = "localhost:3000"


My config/environments/development.rb

file has the following:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }


Here is the German code from ruby โ€‹โ€‹/1.9.1/net/smtp.rb (line 583 is in the middle):

def ssl_socket(socket, context)
  OpenSSL::SSL::SSLSocket.new socket, context

def tlsconnect(s)
  verified = false
  s = ssl_socket(s, @ssl_context)
  logging "TLS connection started"
  s.sync_close = true
  s.connect  # THIS IS LINE 583
  if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
  verified = true
  s.close unless verified


It looks like a segmentation fault occurs when SMTP tries to connect over an SSL ( s.connect

) socket connection . In setup_mail.rb

I tried to install :enable_starttls_auto

both on true

and on false

. I don't get segmentation error when set to false

, but no emails are happening, so this is useless.

I can easily connect to the gmail smtp service by running this command from my Mac:

$ telnet smtp.gmail.com 587


Not sure where to go from here - any suggestions?


source to share

2 answers

I had a very similar error (online / http).

Doing this fixed:

rvm pkg install openssl
rvm pkg install iconv
rvm pkg install readline
rvm reinstall 1.9.3  --with-iconv-dir=$rvm_path/usr  --with-openssl-dir=$rvm_path/usr  --with-readline-dir=$rvm_path/usr




The problem has to do with how Rails interacts with OpenSSL. This post sums it up very well. http://www.22ideastreet.com/debug/smtp-rb14-bug-segmentation-fault/

Fix it to add this to your .bashrc / .zshrc / .bash_profile

export RUBYOPT="-ropenssl" 




All Articles