Rails Mailer在网站上不工作,但在控制台工作



我在用头撞墙。

这就是我的问题。让我们从简单的开始。我有一个联系形式在我的应用程序,它发送电子邮件后,点击提交。此表单在开发模式下完美工作。但是由于一些未知的原因,它不能在生产中工作。

那么,你现在要做什么呢?检查生产。在配置/环境中的Rb ?已经完成了。实际上不止于此-我曾尝试在VPS上的生产模式下使用rails控制台发送邮件。它工作了

UserMailer.send_data(Deliverer.new(full_name: "John Smith", email: "john.smith@yahoo.com", message: "Hello how are you")).deliver_now

我有一个叫做Deliverer的模型,纯粹是为了反垃圾邮件。在我的服务器上进入生产环境中的rails控制台并粘贴此命令后,一封邮件被发送到我的邮箱,就像它应该从网站上工作一样。

这是我的作品。rb文件

require "active_support/core_ext/integer/time"
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.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
config.assets.compile = true
config.active_storage.service = :local
config.force_ssl = true
config.action_mailer.default_url_options = { host: ENV['DOMAIN'] }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
port: '465',
address: 'smtp.seznam.cz',
domain: ENV['DOMAIN'],
user_name: ENV['SMTP_USERNAME'],
password: ENV['SMTP_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true,
ssl: true,
tls: true
}
config.log_level = :info
config.log_tags = [ :request_id ]

config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
config.active_support.report_deprecations = false
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger           = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger    = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end

这是我在/log/production.log

中发现的SMTP错误Net::SMTPFatalError (550 5.7.1 Not authenticated, please use AUTH first.

正如我所说的,这个错误只出现在生产中,当试图从网站发送邮件时。从控制台发送电子邮件在生产工作,从网站的表单不能。正如我所说,在开发过程中一切都很顺利,无论是控制台还是表单本身。

我不知道该怎么办。

TL:博士邮件发送器在开发模式下工作(从网站和rails控制台)。在生产环境中,邮件器只能在rails控制台中工作,而不能在网站中工作。

从网站提交表单后,Mailer在生产中不工作,但在使用rails控制台时工作得很好。在开发过程中没有任何问题。

好的,我已经设法解决这个问题了。

由于某些未知的原因,Rails无法识别ENV[]变量。我真不知道为什么。

但是一旦我将ENV['SMTP_USERNAME']替换为"username@domain.com"and ENV['SMTP_PASSWORD'] with "examplepassword"这一切都开始工作,mailer发送电子邮件到我的收件箱。

我不知道,因为进入rails控制台或irb并使用

把ENV("SMTP_USERNAME")

实际上打印了我的SMTP用户名,同样的事情也发生在密码和其他环境变量上。我不知道出了什么事。

编辑好的,我已经做了一些故障排除。似乎只有配置/环境/生产。rb在访问ENV变量时有问题。我不知道为什么……

相关内容

最新更新