ruby - SSL_connect returned=1 errno=0 state=未知状态 : unknown protocol

标签 ruby ssl nginx openssl smtp

在阅读了很多帖子后,我找不到解决问题的办法。我与 www.smtper.net 进行了测试连接,连接成功。我的 error.log 只告诉我错误:

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=unknown state: unknown protocol


app/controllers/passwords_controller.rb:11:in `create'

可能跟我的nginx设置有关系?

问题

我正在尝试通过 mailgun(或 gmail)配置我的 smtp 但没有成功。 我在 developement.rb 中的配置如下:

config.action_mailer.default_url_options = { :host => "xxxxx:8765" } 
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "mail.google.com",
   :user_name => "xxx@gmail.com",
   :password => "xxxxxx",
   :authentication => :plain,
   :enable_starttls_auto => true
}

错误是在第 11 行创建操作时抛出的:

  AccountMailer.password_reset_email(@account).deliver

我已经在我的开发服务器上安装了 OpenSSL 1.0.1f

追踪

/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:584:in `tlsconnect'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:552:in `do_start'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:518:in `start'
mail (2.7.0) lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
mail (2.7.0) lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
mail (2.7.0) lib/mail/message.rb:2160:in `do_delivery'
mail (2.7.0) lib/mail/message.rb:260:in `block in deliver'
actionmailer (4.2.8) lib/action_mailer/base.rb:543:in `block in deliver_mail'
activesupport (4.2.8) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.8) lib/active_support/notifications.rb:164:in `instrument'
actionmailer (4.2.8) lib/action_mailer/base.rb:541:in `deliver_mail'
mail (2.7.0) lib/mail/message.rb:260:in `deliver'
actionmailer (4.2.8) lib/action_mailer/message_delivery.rb:85:in `deliver_now'
actionmailer (4.2.8) lib/action_mailer/message_delivery.rb:105:in `deliver'
app/controllers/passwords_controller.rb:11:in `create'

最佳答案

如果您尝试此设置并摆脱您当前拥有的所有其他内容,会发生什么:

# /config/environments/development.rb

# Gmail configuration
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'example.com',
  user_name:            ENV['EMAIL_USER'],
  password:             ENV['EMAIL_PASS'],
  authentication:       'plain',
  enable_starttls_auto: true
}

我不确定您是否需要使用 smtper.net,但也许看到这个,即使它很旧,它可能仍然可以工作:

http://blog.napcs.com/2013/07/21/rails_ssl_simple_wa/

您需要设置这些环境变量,因为您显然不应该在 git 存储库中提交凭据。

但也可以查看这些帖子,因为您可能需要为 gmail 做一些其他事情

(Ruby) Getting Net::SMTP working with Gmail...?

Rails 4, how to correctly configure smtp settings (gmail)

关于ruby - SSL_connect returned=1 errno=0 state=未知状态 : unknown protocol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53065740/

相关文章:

http - lua nginx 请求的 POST 大小

ssl - 如何将 Kubernetes Nginx Ingress 与 Consul 和 Consul Connect 集成

ruby-on-rails - 什么时候应该在 Ruby 中使用表达式插值?

ruby - 如何在 Travis-CI 上为 TensorFlow 构建共享库

php - 403 Forbidden - 该页面需要客户端证书作为身份验证过程的一部分

ssl - wso2is - 添加新的 keystore

python - Django 没有正确重定向

Ruby:为什么 1.025.round(2) 四舍五入为 1.02?

ruby-on-rails - 这些奇怪的字符是什么意思?

azure - 如何将私钥证书 (.pfx)、公钥证书 (.cer) 上传到 Azure WebApp