[英]Rails 4 Mailer not working in production Digital Ocean server
I have a simple contact form in my app that uses my Gmail account to send the e-mail to another Gmail account. 我的应用程序中有一个简单的联系表单,该表单使用我的Gmail帐户将电子邮件发送到另一个Gmail帐户。 For some reason it sends mails perfectly in development but no in production.
由于某种原因,它在开发中完美地发送了邮件,但在生产中却没有。 I'm hosting my website in a DigitalOcean one-click Rails app.
我将自己的网站托管在DigitalOcean一键式Rails应用程序中。 When I try to send a mail in the live version the website hangs for a bit and displays "We're sorry, but something went wrong."
当我尝试以实时版本发送邮件时,网站挂了一段时间,并显示“很抱歉,出了点问题。”
Gemfile 的Gemfile
#Mailer
gem 'mail'
development.rb 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 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
I got an answer from the support desk and you can remedy this issue by prioritizing IPv4 over IPv6 in the etc/gai.conf
file by un-commenting the line 我从服务台获得了答案,您可以通过取消注释该行,在
etc/gai.conf
文件中通过将IPv4优先于IPv6来解决此问题。
#precedence ::ffff:0:0/96 100
The reason behind this is that Digital Ocean blocks outgoing SMTP requests over IPv6 by default. 其背后的原因是,默认情况下,Digital Ocean会阻止通过IPv6的传出SMTP请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.