我查过google和stackoverflow,但没法搞清楚。
我有一个使用Ruby1.8.7的Rails2.3.9应用程序,试图通过SMTP发送电子邮件,如下所示:

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

我的应用程序回溯如下:
/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'

最佳答案

我想出来了。我的ISP正在阻塞端口25,因此我必须更改配置:

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

关于ruby-on-rails - Rails 2.3.9和SendGrid,连接被拒绝-本地主机上的connect(2),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5223858/

10-09 04:29