2015-12-02 5 views
0

Я использую Mandrill в своем приложении Rails для отправки транзакционной электронной почты. Я использую драгоценный камень 'mandrill-api', и я настроил его в соответствии с документацией.API Mandrill с использованием Rails 4.2.5 Excon :: Errors :: SocketError

Он отлично работает на производстве, но в местных Raides ошибке:

Unable to verify certificate, please set `Excon.defaults[:ssl_ca_path] = path_to_certs`, 
`ENV['SSL_CERT_DIR'] = path_to_certs`, `Excon.defaults[:ssl_ca_file] = path_to_file`, `ENV['SSL_CERT_FILE'] = path_to_file`, 
`Excon.defaults[:ssl_verify_callback] = callback` (see OpenSSL::SSL::SSLContext#verify_callback), 
or `Excon.defaults[:ssl_verify_peer] = false` (less secure). 

Я не понимаю, почему он работает на производстве, а не в местных?

Вот мой конфиг:

Gemfile

source 'https://rubygems.org' 

ruby '2.2.3' 

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.5' 
# Use postgresql as the database for Active Record 
gem 'pg', '~> 0.15' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use Unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

group :development, :test do 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    #gem 'byebug' 
    gem 'better_errors' 
    gem 'binding_of_caller' 
    gem 'quiet_assets' 
    gem 'pry-rails' 
end 

group :development do 
    # Access an IRB console on exception pages or by using <%= console %> in views 
    gem 'web-console', '~> 2.0' 

    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
end 

group :production do 
    gem 'rails_12factor' 
end 

# Privacy 
gem 'figaro' 

# Heroku 
gem 'heroku' 

# Private access! 
gem 'lockup' 

# Mails 
gem 'mandrill-api' 

development.rb

Rails.application.configure do 
    # Settings specified here will take precedence over those in config/application.rb. 

    # In the development environment your application's code is reloaded on 
    # every request. This slows down response time but is perfect for development 
    # since you don't have to restart the web server when you make code changes. 
    config.cache_classes = false 

    # Do not eager load code on boot. 
    config.eager_load = false 

    # Show full error reports and disable caching. 
    config.consider_all_requests_local  = true 
    config.action_controller.perform_caching = false 

    # Don't care if the mailer can't send. 
    config.action_mailer.raise_delivery_errors = false 

    # Print deprecation notices to the Rails logger. 
    config.active_support.deprecation = :log 

    # Raise an error on page load if there are pending migrations. 
    config.active_record.migration_error = :page_load 

    # Debug mode disables concatenation and preprocessing of assets. 
    # This option may cause significant delays in view rendering with a large 
    # number of complex assets. 
    config.assets.debug = true 

    # Asset digests allow you to set far-future HTTP expiration dates on all assets, 
    # yet still be able to expire them through the digest params. 
    config.assets.digest = true 

    # Adds additional error checking when serving assets at runtime. 
    # Checks for improperly declared sprockets dependencies. 
    # Raises helpful error messages. 
    config.assets.raise_runtime_errors = true 

    # Raises error for missing translations 
    # config.action_view.raise_on_missing_translations = true 

    # Mails 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.perform_deliveries = true 

    # Devise 
    #config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 

    # TODO: do it with a template: http://blog.nvisium.com/2014/10/mandrill-devise-and-mailchimp-templates.html 
    config.action_mailer.smtp_settings = { 
    :address => 'smtp.mandrillapp.com', 
    :port  => 587, # ports 587 and 2525 are also supported with STARTTLS 
    :enable_starttls_auto => true, # detects and uses STARTTLS 
    :user_name => ENV['MANDRILL_USERNAME'], 
    :password => ENV['MANDRILL_API_KEY'], # SMTP password is any valid API key 
    :authentication => 'login', # Mandrill supports 'plain' or 'login' 
    :domain => ENV['HOST'], # your domain to identify your server when connecting 
    } 
end 

mandrill.rb

require 'mandrill' 

# Use an environment variable instead of placing the key in source code 
MANDRILL = Mandrill::API.new ENV['MANDRILL_API_KEY'], true 

Fonction поднимая ошибку только в местные:

def send_short_email(subject, message, receiver) 
    inner_message = { 
     to: [{name: receiver.name, type: 'to', email: receiver.email}], 
     subject: subject, 
     html: message, 
     text: message, 
     from_email: ENV['DEFAULT_EMAIL_SENDER'] 
    } 
    MANDRILL.messages.send inner_message 
    logger.debug inner_message 
    end 

Я попытался изменить настройки, хосты или ключ API, но ничего не работает. И об этой проблеме не упоминается в документации по драгоценному камню.

У вас есть идея?

Спасибо!

Селин

+0

Это вопрос сертификат SSL с EXCON. Может быть связано или такая же проблема, как и эта: https://github.com/excon/excon/issues/473 – Casper

+0

И это может быть полезно прочитать также: https://github.com/excon/excon/ Проблемы/239 – Casper

+0

Я читал их, но я не знаю, как я могу решить проблему. :-(Может быть, удаление и повторная установка Ruby? –

ответ

1

Как было предложено Каспер в своем комментарии, я отредактировал мой файл development.rb пропустить проверку сертификата.

development.rb

require 'excon' 
Rails.application.configure do 
    ... 
    Excon.defaults[:ssl_verify_peer] = false 
end 
Смежные вопросы