在阅读了很多帖子后,我找不到解决问题的办法。我与 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 - SSL_connect returned=1 errno=0 state=未知状态 : unknown protocol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53065740/