我的应用中有一个简单的联系表单,它使用我的Gmail帐户将电子邮件发送到另一个Gmail帐户。出于某种原因,它在发展中完美地发送邮件但在生产中没有。我在DigitalOcean一键式Rails应用程序中托管我的网站。当我尝试在实时版本中发送邮件时,网站会挂起一些并显示“我们很抱歉,但出了点问题。”
的Gemfile
#Mailer
gem 'mail'
development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 465,
:user_name => 'foo@gmail.com',
:password => 'foo',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
end
production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.action_mailer.default_url_options = { host: 'foo.com.mx' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 465,
:user_name => 'foo@gmail.com',
:password => 'foo',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
end
答案 0 :(得分:0)
我从支持部门得到了答案,您可以通过取消注释该行来优先处理etc/gai.conf
文件中的IPv4 over IPv6来解决此问题
#precedence ::ffff:0:0/96 100
这背后的原因是Digital Ocean默认阻止通过IPv6传出SMTP请求。