在我配置为使用服务发布电子邮件后,postmark
我遇到了一些环境问题。development
staging
简短说明:portmark 在以下情况下使用“ok”运行良好,并且当出现DeserializationError
活动作业时,它似乎正在失败,因为它正在查看用户 ID 是否存在于生产数据库中。
开发环境:
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
暂存环境
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
生产环境
devise mailing -> ok
deliver_later -> ok
deliver_now -> ok
长解释:
当我在这两个环境中并使用devise
确认说明进行请求时,它会发送一个指向此电子邮件的链接,其中包含一个production
带有指向错误页面的令牌的 url。
最有趣的是,在我从开发或登台 envs 控制台发送电子邮件后,我打开了 sidekiq 仪表板,我发现当生产上没有与请求发送此电子邮件的 id 相关联的用户 id 时(来自其他环境),此邮件失败并显示以下消息:
安慰:
> Rails.env
"development"
> @user.id
22
> UserMailer.welcome(@user).deliver_later
Sidekiq 错误:
ActiveJob::DeserializationError: 尝试反序列化参数时出错: 找不到 'id'=22 的用户
安慰:
> Rails.env
"staging"
> @user.id
15
> UserMailer.welcome(@user).deliver_later
Sidekiq 错误:
ActiveJob::DeserializationError: 尝试反序列化参数时出错: 找不到 'id'=15 的用户
一些配置:
Rails 5.0.1
postmark (1.14.0)
postmark-rails (0.18.0)
生产.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "www.mywebsite.com" }
...
发展.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
...
分期.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "website.herokuapp.com" }
...
sidekiq.yml
:concurrency: 3
:timeout: 60
:verbose: true
:queues:
- default
- mailers
Obs:这三个环境都使用不同的邮戳 API 密钥。
更新 1
这里是发展:
发展.rb
Rails.application.configure do
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
我用gmail更改为旧配置,问题仍然存在......
发展.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'gmail.com',
user_name: ENV['GMAIL_ADDRESS'],
password: ENV['GMAIL_APP_PASSWORD'],
authentication: "plain",
enable_starttls_auto: true
}
config.action_mailer.default_url_options = {host: "localhost:3000"}
end
更新 2:
我还试图去过去的邮件正在工作的分支,但什么也没有(我重新启动了服务器)......