Configuration rails3 actionMailer for Google Compu

2019-03-04 07:18发布

问题:

Getting a:

Timeout::Error (execution expired):
  app/controllers/acts_controller.rb:192:in `send_message'

GCE requires sendgrid and following there indications I adapted the port to "2525" as per GCE's documentation. So the environment.rb file is

require File.expand_path('../application', __FILE__)

Paperclip.options[:command_path] = "/usr/bin/"

ActionMailer::Base.smtp_settings = {
  :user_name => ENV["SENDGRID_USERNAME"],
  :password => ENV["SENDGRID_PASSWORD"],
  :domain => ENV["DOMAIN"],
  :address => 'smtp.sendgrid.net',
  :port => 2525,
  :authentication => :plain,
  :enable_starttls_auto => true
}

# Initialize the rails application
Myapp::Application.initialize!

The environment variables are defined in a yaml file with

SENDGRID_USERNAME:  'my_username'
SENDGRID_PASSWORD:  'pswd'
DOMAIN:  'domain.tld'

This being still in development mode, development.rb defines

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net' }

What could be at the source of the timeout?

EDIT: On the assumption of a bad connection

telnet smtp.sendgrid.net 2525
Trying 5.153.47.202...
Connected to smtp.sendgrid.net.

回答1:

in your development.rb try to modify the config.action_mailer.default_url_options to:

config.action_mailer.default_url_options = {
  :host => 'smtp.sendgrid.net',
  :port => 2525
}