问题
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