Rails 2.3.9 and SendGrid, Connection refused - connect(2) on localhost

巧了我就是萌 提交于 2020-01-02 07:04:44

问题


I've looked through Google and StackOverflow and can't figure this out.

I've got a Rails 2.3.9 app using Ruby 1.8.7, trying to send email through SMTP like so:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => "smtp.sendgrid.net",
  :port => '25',
  :domain => "************.com",
  :authentication => :plain,
  :user_name => "***********",
  :password => "**********"
}

My app backtrace looks like this:

/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/net/smtp.rb:551:in `initialize'
/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/net/smtp.rb:551:in `open'
/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/timeout.rb:67:in `timeout'
/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/timeout.rb:101:in `timeout'
/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/Users/jared/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/net/smtp.rb:525:in `start'
/Users/jared/.rvm/gems/ruby-1.8.7-p334/gems/actionmailer-2.3.9/lib/action_mailer/base.rb:682:in `perform_delivery_smtp'
/Users/jared/.rvm/gems/ruby-1.8.7-p334/gems/actionmailer-2.3.9/lib/action_mailer/base.rb:523:in `__send__'
/Users/jared/.rvm/gems/ruby-1.8.7-p334/gems/actionmailer-2.3.9/lib/action_mailer/base.rb:523:in `deliver!'
/Users/jared/.rvm/gems/ruby-1.8.7-p334/gems/actionmailer-2.3.9/lib/action_mailer/base.rb:429:in `deliver'
/Users/jared/rails/********/app/models/user.rb:160:in `send_welcome_email'
/Users/jared/rails/*********/app/controllers/users_controller.rb:35:in `create'

回答1:


I figured it out. My ISP was blocking port 25, so I had to change my configuration:

ActionMailer::Base.smtp_settings = {
  :address => "smtp.sendgrid.net",
  :port => '587',
  :domain => "**********.com",
  :authentication => :plain,
  :user_name => "************",
  :password => "*********",
  :enable_starttls_auto => true
}


来源:https://stackoverflow.com/questions/5223858/rails-2-3-9-and-sendgrid-connection-refused-connect2-on-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!